From Laravel Blade to Vue.js + API [Live-coding Example]

Поделиться
HTML-код
  • Опубликовано: 29 сен 2024
  • For those who haven't started with Vue.js - you can watch me adapting that quickly, in 22 minutes, in (almost) live-mode.
    We take a typical Laravel page of catalog with categories and products, and we transform that into Laravel API, then consuming it from Vue.js.
    Repository: github.com/Lar...
    Wanna dive a bit deeper into Laravel + Vue? I have a full 2-hour course with a practical project "Vue.js 3 + Laravel 9: CRUD with SPA": laraveldaily.t...
    - - - - -
    Support the channel by checking out my products:
    - My Laravel courses membership: laraveldaily.t...
    - Laravel QuickAdminPanel: bit.ly/quickad...
    - Livewire Kit Components: livewirekit.com
    - - - - -
    Other places to follow:
    - My weekly Laravel newsletter: bit.ly/laravel-...
    - My personal Twitter: / povilaskorop

Комментарии • 268

  • @bru6626
    @bru6626 4 года назад +75

    This type of tutorial is what i want. Straight to the point

  • @aungminhein2178
    @aungminhein2178 Год назад

    Easiest to understand ever

  • @MrDLashley
    @MrDLashley 4 года назад +2

    Hi Povilas , Great tutorial, and I was wondering if you were going to follow it up with an insert / update example

    • @PovilasKorop
      @PovilasKorop 4 года назад +1

      I didn't plan to, but seems like the audience want more content about spa and Vue with Laravel, so yes will figure something out.

  • @shahzodkhusinov1041
    @shahzodkhusinov1041 4 года назад

    Great

  • @satria7806
    @satria7806 3 года назад

    is there any chance for using this cache with Query PDO?

  • @PositiveZahid
    @PositiveZahid 4 года назад

    Yes.. it is nice .....

  • @MarcHershey
    @MarcHershey 3 года назад +1

    2:12 "as good practice... controllers should be named in singular form..." then puts ProductsController lol

  • @dineshsaxena9560
    @dineshsaxena9560 4 года назад

    Question- will existing big laravel project based on blades (view) affects by installing vue.js for frontend.
    Like wise - Existing routes will affect or any other controller issue?
    For example- i want to create one page with Vue. Ratio will be 99% blade and 1% vue.
    Will both are working fine?
    Please answer asap...
    Thanks

    • @LaravelDaily
      @LaravelDaily  4 года назад

      It depends on how you code it. Vue may conflict with jquery if you use it, your old Controllers may conflict with API Controllers if you miss some details. So it depends on your coding abilities, not on Laravel or Vue.js

    • @dineshsaxena9560
      @dineshsaxena9560 4 года назад

      @@LaravelDaily - conflict word makes sense. Thanks

  • @onessimuslyngdoh289
    @onessimuslyngdoh289 4 года назад +85

    Npm run watch and you don't need to run npm install everytime

    • @Formula7Driver
      @Formula7Driver 3 года назад +7

      npm install isn't needed in any case, it's enough to run it just once. npm run watch actually removes the need to run npm run dev multiple times

  • @LaravelDaily
    @LaravelDaily  4 года назад +20

    Wanna dive a bit deeper into Laravel + Vue? I have a full 2-hour course with a practical project "Vue.js 3 + Laravel 9 SPA: CRUD with Auth": laraveldaily.teachable.com/p/vue-js-3-laravel-9-crud-with-spa-and-auth?

    • @muhammadharis-lo9nv
      @muhammadharis-lo9nv 2 года назад

      Hi sir can you make tutorial review product laravel vue js pusher

  • @peo6264
    @peo6264 4 года назад +14

    From the bottom of my heart, thank you, honestly, a big thank you! You once again helped me so much! I work hard on a project and am REALLY struggling sometimes, but your videos are awesome, they're giving me hope, it keeps me motivated, it makes me wanna keep on trying and moving forward. I will definitely subscribe to your courses to support you and what you are doing ! Best regards

  • @zkabadu
    @zkabadu 2 года назад +1

    Uh, setting loading to false in the resolve part of only one AJAX request is a bad practice. You should return the promise from both loading methods, wrap them in a Promise.all() and then, if both promises are resolved, set loading to false. That is the correct way. But to be fair: you're a PHP guy and not a JavaScript one ;)

  • @manishprabhakaran1561
    @manishprabhakaran1561 3 года назад +1

    Can I install vue 3 with an existing Jetstream/Livewire project. I tried doing it, but getting a few errors. Will doing it collide with any internal configuration.??. Please help me out.

  • @windigo000
    @windigo000 3 года назад +3

    15:18 - consistency 😁
    1) data: function() { ...
    2) mounted() { ...
    I am paying attention sometimes :P

  • @BradleyAhrens
    @BradleyAhrens 4 года назад +11

    Thanks for the video, Pavilas! Just wanted to note that you can also just run `npm run watch` instead of `npm run dev` each time. 😉

    • @MohamedZiada
      @MohamedZiada 4 года назад

      @Povilas Korop , Thanks for the video, Or u can `npm run dev` without each time run `npm install`

  • @Michel39511
    @Michel39511 4 года назад +24

    Good tutorial, but you should put API calls in created, not mounted. Created is ran when the component is alive, mounted is ran when the DOM of the component is rendered.

  • @mauriciosorto8163
    @mauriciosorto8163 4 года назад +6

    Great stuff!
    I have been researching about this matter, and found a lot of videos but yours is the most clear and simple to understand.
    Really, really good content, thanks!

  • @tallaljamshed4880
    @tallaljamshed4880 4 года назад +6

    I find your explanation quite easy to understand. It will be much appreciated if you could make a tutorial series on vue.js.

    • @PovilasKorop
      @PovilasKorop 4 года назад +6

      Thanks, will think about it.

  • @RadomPlayers
    @RadomPlayers 3 года назад +1

    What are the benefits of using Vue with laravel? I assume you can do the same things right?
    The only problem I see is that Vue uses axios and for laravel you need to use ajax.

    • @ShabbeyRoadMusic
      @ShabbeyRoadMusic 3 года назад +1

      Same question here. I've only browsed the Vue docs but I don't really see the point. Since I'm running a business, I don't see the point of learning another product unless it provides a more efficient & readable way to do something that I already do, or it provides a way to do something I *can't* currently do. Vue doesn't seem to meet either of those requirements for me. But I'd welcome the thoughts of others on this.

  • @gurbeigekolekter8831
    @gurbeigekolekter8831 3 года назад +5

    I love watching your videos. I hope you'll create one similar to this for Vue 3 in the future, if you have the time.

  • @hesami13
    @hesami13 Год назад +1

    It was simple and comprehensive.❤
    Please make a video about livewire and its difference with VueJS in laravel.
    Is it necessary to go to VueJS even though there is livewire?
    And their relationship with AlpineJs

  • @emersonslvm
    @emersonslvm 4 года назад +4

    Pretty nice video! Congrats, from Brazil 🇧🇷

  • @sfrzid
    @sfrzid 4 года назад +3

    That's loading state to false should be in finally scope, bcz when request failed that loading still show forever

    • @aqshalzakki2526
      @aqshalzakki2526 4 года назад

      yeah in finally block, but that should be just fine for starting point

  • @pietrosavastano9940
    @pietrosavastano9940 3 года назад +1

    why dont u use npm run watch

  • @manishprabhakaran1561
    @manishprabhakaran1561 3 года назад +2

    Your heart can hear exactly what beginners are suffering from....and you serve the needs. Thank you very much🙏 for the clear cut video you've done🏆.
    Continue with your good work. Good luck.

  • @403gtfo
    @403gtfo 4 года назад +3

    Awesome video. I really needed a refresher in Vue, been 6 months since I used it with laravel.
    Should just be able to use 'npm run watch' to have it compile after every save automatically yea?
    Saves having to manually run the commands :)

  • @ricko13
    @ricko13 3 года назад +1

    In 6:29 your advice is to store the price/money in Integer... but what if the new developer forgets to transform that and now your client doesn't have $10.85 but $1085 , that will be chaos ( U_U)

  • @shabastech
    @shabastech Год назад +1

    the best 💯 so far

  • @tannercampbell
    @tannercampbell 4 года назад +1

    Why do you install Vue.js in the devDependencies and not the dependencies? Doesn't that require an additional npm command when running the application in a production environment?

    • @PovilasKorop
      @PovilasKorop 4 года назад +1

      Good catch, my mistake there, since I was working on a local machine I didn't notice. It should be dependencies, yes.

    • @tannercampbell
      @tannercampbell 4 года назад +1

      Povilas Korop no worries, thanks for the clarification. BTW love your videos you do a fantastic job teaching Laravel enthusiasts!!

  • @sergeyk7285
    @sergeyk7285 3 года назад

    The example works on a localhost, an error appears on the server
    src="{{ mix('js/app.js') }}" Failed to load resource: the server responded with a status of 404 (Not Found)
    How to fix it?

  • @АлександрАболмасов-т5е

    Я Английский сюда захожу подучить =) Идеально произношение! Спасибо!

  • @nataliapalweski2072
    @nataliapalweski2072 3 года назад

    Almost 100% of tutorial on google and youtube only talking about using VueJS as a component but sometimes we don't want to use VUE as a component we want only to use in Blade files for frontend interactivity. for doing this we separate have to call VueJS cdn and put in Blade files which is annoying..
    is there anyway to load Vue js as library in laravel mixing and call "new Vue" in blade files?

  • @Sdirimohamedsalah
    @Sdirimohamedsalah 11 месяцев назад

    Great! 99% of tutors don’t cover building project

  • @masterpreshy9614
    @masterpreshy9614 3 года назад +1

    Best Teacher!

  • @the_coding_traveller
    @the_coding_traveller 5 месяцев назад

    actually made a tutorial that made me motivated to learn it. just simple and clear! Thank you for the good work!!

  • @carlosquintero1968
    @carlosquintero1968 2 года назад

    Just to be clear to all ppl starting, us dont need to run npm install && npm run dev each time you have changes, npm install muyst be run only for install the project or if u add new packages to the package.json manually

  • @francisco25657
    @francisco25657 2 года назад +1

    This video is gold

  • @FISS007
    @FISS007 2 года назад

    what if the first api call takes longer than the second one ? you would then display the page even if the first api call is still waiting for the data. I kknow this is a simple example, but you should at least mention that you need to somehow join on both api calls imo.
    Nice video though :)

  • @VadimBesedin
    @VadimBesedin 4 года назад +2

    Clear and straight to the point. Thank you for your time and for sharing your knowledge!

  • @taiwoolatmi3594
    @taiwoolatmi3594 4 года назад +1

    This is awesome tutorial, taking Vue like slicing cucumber with sharp knife, Very straight forward, We appreciate you so much, Pls help Us with a vidoe on the explanation of the vue Pagination part.

  • @copinman
    @copinman 4 года назад +1

    Hi, im kinda new with blade and laravel but im been doing some complex stuff too yet does anyone can explain to me why use vue.js instead of the simple blade syntax that doesnt need to compile. Thanks 😃

    • @ShabbeyRoadMusic
      @ShabbeyRoadMusic 3 года назад

      Good question. I always wonder about these tools that keep coming out that don't seem to do anything new. They just seem to do what something else already does in a different way.

  • @davidsyengo1893
    @davidsyengo1893 3 года назад

    instant sub, great work, vivid explanation.

  • @curiousbd8115
    @curiousbd8115 4 года назад

    You are awesome

  • @kelvezu1585
    @kelvezu1585 4 года назад +3

    I'm starting not to use blade. I love how dynamic Vue is.

  • @adriennecool69
    @adriennecool69 3 года назад +1

    You are the best!! Thank you so much for this amazing tutorial. Developers like you are responsible for the success of so many other developers!

  • @Daily-digital
    @Daily-digital 3 года назад +1

    grateful to You. Can we have a series of laravel 8 + react/vs with any live project tutorial...

  • @hamdaniash-siddiq5021
    @hamdaniash-siddiq5021 4 года назад +1

    You are really the best teacher of laravel. U make things clear by doing simple things.

  • @bassamdarawshi
    @bassamdarawshi 3 года назад

    hi
    what if i have multiple component that need to get data from same request
    for example if i have multiple component that show info about product
    where to put the axios request or
    what is the best solution in this case?

  • @hasanchishti6428
    @hasanchishti6428 2 года назад

    You are a real Hero. Thank you for this amazing video

  • @iordanistsapanidis4021
    @iordanistsapanidis4021 3 года назад

    How to work with vuejs inside providers directory in order to use view composers?

  • @bogdanmarian3786
    @bogdanmarian3786 4 года назад +3

    Thank you for having the patience to explain every step, this is a great tutorial !

  • @limuelmendoza5356
    @limuelmendoza5356 2 года назад

    will this cause me to have an SPA website or will it remain the same normal website?

  • @mwacharojohn9318
    @mwacharojohn9318 Год назад

    thank you saved me .several concepts in one video

  • @angelo.piletti
    @angelo.piletti 3 года назад

    Excelente vídeo! Então eu não preciso fazer nenhum tipo de intalação npm ou composer para usar o vue no laravel ^8.x?

  • @JohnSmith-zl8rz
    @JohnSmith-zl8rz 4 года назад

    That is SEO friendly?

  • @krisssachintha
    @krisssachintha 3 года назад

    you saved my day, thank you so much. Liked and shared

  • @sanjeetbisht
    @sanjeetbisht 3 года назад

    What editor are you using for laravel?

  • @techman4396
    @techman4396 3 года назад

    can you do same tutorial for Vue 3?

  • @haziriamin
    @haziriamin 3 года назад

    Thank you.. very easy to understand..

  • @djnkuli
    @djnkuli 4 года назад +1

    I dont know what to say but Thank you! 😊 🙏

  • @jaker9007
    @jaker9007 2 года назад

    Huge thanks mate! Saved me a lot of time!

  • @gojamoja6719
    @gojamoja6719 2 года назад +1

    You are a blessing for laravel learners

  • @ericksanabria5657
    @ericksanabria5657 2 года назад

    Amazing job. Thank you

  • @zayedmohamed737
    @zayedmohamed737 3 года назад

    does this way affect the SEO of the website ?

  • @Imagine51204
    @Imagine51204 4 года назад +5

    I just starting reading about vue two days back and now this helps me alot as I already know laravel.
    So basically mounted here stands for on ready similar to Jquery
    Thanks

  • @69aantu
    @69aantu 4 года назад +1

    I find your explanation quite easy to understand. thanks.
    One question please, api return as { "data" : [ ] }. is it possible, return as { "categories" : [ ] } ? that means "categories", "products" instead of "data".

    • @halilcakar5157
      @halilcakar5157 4 года назад +2

      Hey, yes it's possible. You can see on laravel.com/docs/7.x/eloquent-resources#data-wrapping from laravel source :) And you can even disable it too =)

    • @69aantu
      @69aantu 4 года назад +1

      @@halilcakar5157 thank you very much. I got it. $wrap.

  • @edmartinez5345
    @edmartinez5345 4 года назад +1

    Thank you so much. Please keep generating great content! Cheers to you.

  • @JohnSmith-zl8rz
    @JohnSmith-zl8rz 4 года назад

    why load the inside the body and not in the head like Laravel do by default???

  • @cyrillembia
    @cyrillembia 2 года назад

    Verry usefull. Thanks

  • @niketjoshi5877
    @niketjoshi5877 4 года назад +1

    Hey, you are doing exceptional job by teaching us good stuff in latest framework. I would like to tell you could you please make vue js tutorial videos with laravel. From basic to advance level so user who know laravel but not vue js can learn that from your video and example like you make.
    Hope you provide such a good solution for this.

    • @PovilasKorop
      @PovilasKorop 4 года назад +1

      Thanks, will think about it.

    • @daviddeleon3411
      @daviddeleon3411 4 года назад

      @@PovilasKorop I love how php master teach us js thank you sir

  • @vanessayessa842
    @vanessayessa842 3 года назад

    Is it possible to get vue inside laravel project without run npm?? Thanks!

  •  4 года назад

    Tkanks video ! Việt nam không hiểu chỉ xem thôi 🤣

  • @Jes14-t3b
    @Jes14-t3b 3 года назад

    I'm motivated now to learn SPA with Laravel and Vue, thanksss.

  • @netpok
    @netpok 4 года назад +1

    Your example of setting the this loading variable is wrong, axios returns a promise and there is no guarantee about which will finish first.
    What you actually need to do:
    - return both promise from their methods
    - wrap them in promise.all
    - define a then on the new promise to set the loading only after both of them are finished

    • @PovilasKorop
      @PovilasKorop 4 года назад

      Thanks for the notice! I agree it could be improved with your suggestion, but the goal with this video was to show the absolute beginners how Vue works in general, any additional theory about promised would be a step for overwhelming them. So, one step at a time, I will probably need to shoot followup videos or a full course.

    • @JouvaMoufette
      @JouvaMoufette 4 года назад

      Mmm I like your method rather than my method of simply using variables to track if they're all complete. I did catch the exact same concern you had and mention you needed to look for both callbacks to complete, but your solution is more elegant than mine.

  • @mateuspokemon01
    @mateuspokemon01 4 года назад +1

    Great! That's exactly what I needed! Thanks for sharing!

  • @sebot1
    @sebot1 3 года назад

    My God...
    This video should called like "Understanding the Laravel+Vue+Api in 22 minutes". This is the first vid in a million that i watched and understood all of the main point of these two frameworks.
    Just awesome!

  • @sagytt
    @sagytt 3 года назад

    Greate Video! You know how to pass knowledge very efficiently.

  • @ridwanhaqi6834
    @ridwanhaqi6834 3 года назад

    Thank you verymuch

  • @BrnBar
    @BrnBar 3 года назад

    How can i use Vue-meta in this scenario? I can hardcode some meta information directly inside welcome.blade.php. Since, that is the first template rendered, it will load everytime. But then, if i want to make a dynamic title, how can i access to my main title which is coming from backend. Any idea?

  • @topmemesforyou5848
    @topmemesforyou5848 3 года назад

    Thanks for this video, please do more on Vue.js + Laravel

  • @LaravelLover
    @LaravelLover 3 года назад

    Very clear explanation from scratch. Can you please tell me why some peoples are using Vue project and laravel project separately, they can fetch the backend info from the Laravel and get into the vue using api endpoints. What is the reason behind the scene, what is good practice to create the large application, Create a single application containing vue and laravel or separate applications for both?

    • @PovilasKorop
      @PovilasKorop 3 года назад +1

      From what I've seen, that separation of the project happens in bigger teams when there is a separate person/team working ONLY on the front-end and works with only their part of the project, also if there's a mobile app involved or a bigger structure, then it's worth creating separate repositories. Otherwise, one single application is fine. But generally, it depends on how it is more convenient FOR YOU, not just "following good practice".

    • @LaravelLover
      @LaravelLover 3 года назад

      @@PovilasKorop Thanks Now I understood clearly.

  • @programmingwithsami1
    @programmingwithsami1 8 месяцев назад

    Very very helpful ❤

  • @KastsEcho
    @KastsEcho 2 года назад

    One change I'd make is wrap both method calls in the mounted function within a try catch block, and then set loading to false. that way, you'd ensure both api calls loaded before rendering.

  • @eleadnetworks3876
    @eleadnetworks3876 3 года назад

    I love this. very straight forward and understandable. Thanks. I will like to get a full course on Laravel, vue, Laravel vue. I don't mind paying

  • @lucagambetta5842
    @lucagambetta5842 4 года назад

    good newbie tutorial, but you don't need to run `npm run install` every time you change your code, only `npm run dev` (or `npm run prod` on production). It's too much for a newbie tutorial, but the first thing to learn when dealing with multiple API call into the mounted() method is how to chain the API calls using axios.all() (or Promise.all() which is nearly the same)

  • @aomo5293
    @aomo5293 4 года назад

    Hello;
    Thank you for share. Please can you show us an example of how to use laravel translation in vuejs.
    Thank you and have a nice time;

  • @woutervisser5987
    @woutervisser5987 3 года назад

    Great tutorial! Thank you!
    If you run in to a problem with the application not renewing. Check your cache. Quite obvious but I didn't think of it myself :D

  • @saravanangilli007
    @saravanangilli007 3 года назад

    Excelent! Thanks for wonderful explaination.

  • @KangJangkrik
    @KangJangkrik 4 года назад

    I'm using both, for product listing blade is better and dynamic widgets (like graph and chart) only possible with vue. Perfect combo 👌

  • @indrajitdas9595
    @indrajitdas9595 3 года назад

    Hello Sir, your videos are awesome . I have a question on axios .How I can use a laravel named route in axios ? Instead of URL?

  • @sirmiles1820
    @sirmiles1820 4 года назад

    All likes and no dislikes.
    Yeah after my comment there will always be that person.

  • @Undercraftt
    @Undercraftt 3 года назад

    Thanks a lot for this example... very clear.

  • @jeffersoncarvalho2566
    @jeffersoncarvalho2566 4 года назад

    Does the front component name on the div #app needs to be the same of Front.vue ?

    • @PovilasKorop
      @PovilasKorop 4 года назад

      No, div id="app" is for the whole application, and Front.vue is for , so in other words, front page is one level below the app.

  • @h.serhan9862
    @h.serhan9862 3 года назад

    You are the best!

  • @Paltibenlaish
    @Paltibenlaish 3 года назад

    It will be nice to add a lazy loader for products so the user can actually see something fast

  • @edmartinez5345
    @edmartinez5345 4 года назад

    My API doesn't seem to return the "data" field described in 5:33...any idea how to put it in place? i upgraded from Larvel 5.5 to 6.0,I'm thinking it's because of this it may not be automatic. Help!

    • @PovilasKorop
      @PovilasKorop 4 года назад

      Not sure, from what I remember API Resources had "data" from the very beginning, but you should double-check this docs page with choosing previous Laravel version, maybe you will find something: laravel.com/docs/7.x/eloquent-resources

    • @edmartinez5345
      @edmartinez5345 4 года назад

      @@PovilasKorop Thanks!

  • @debasisacharya3604
    @debasisacharya3604 3 года назад

    Thank you sir. I was searching for this kind of video and finally i got it. it helped me alots.

  • @Saikiasian
    @Saikiasian 2 года назад

    thank you for another great tutorial. Really helps us beginners out.

  • @phunguyentrong722
    @phunguyentrong722 4 года назад

    thanks so much

  • @PildorasMusicales
    @PildorasMusicales 3 года назад

    EXCELENT!