Тёмный

Laravel Form: From Blade to Vue.js + API 

Laravel Daily
Подписаться 143 тыс.
Просмотров 56 тыс.
50% 1

A demo-project with (almost) live-coding the transformation: Laravel-only form changed to a Vue.js component with submission, success message, and validation - all handled in the Vue component.
0:00 Intro and Original Laravel Form
1:09 Replace Blade Form with New Vue.js Component
3:45 Compiling JavaScript with "npm install" and "npm run dev"
5:06 Loading Categories for Dropdown in the Form
7:26 First Successful Submit of the Form
11:36 Short Notice about CSRF Token
12:05 Showing Success Message Alert
13:17 Showing Validation Errors
Repository: github.com/Lar...
Related video:
- Learn Vue.js Basics from Default Laravel Installation • Learn Vue.js Basics fr...
- - - - -
Try our Laravel QuickAdminPanel: bit.ly/quickad...
Enroll in my Laravel courses: laraveldaily.t...

Хобби

Опубликовано:

 

17 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 74   
@LaravelDaily
@LaravelDaily 4 года назад
If you want more practice on how forms and datatables work with Vue.js in Laravel, I have a full 2-hour course "Vue.js + Laravel: CRUD with SPA" laraveldaily.teachable.com/p/vue-laravel-crud-spa
@dr.adam.nielsen
@dr.adam.nielsen 4 года назад
You could also use Vue to craft components , etc. and then use these components in blade. So you get the best of both, Laravel Blade Engine and Vue.
@beatnu187
@beatnu187 4 года назад
I really love your video's, you explain everything so well, thank you alot!
@dr.adam.nielsen
@dr.adam.nielsen 4 года назад
The magic why the CSRF token works is actually in `resources/assets/js/bootstrap.js` the line `window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;`
@wintechpro4107
@wintechpro4107 4 года назад
True, and if you use jquery you can add $.ajaxSetup that will do the same thing.
@ckmirafss
@ckmirafss 4 года назад
Thanks for using npm run watch! 🎊🎉🎉
@kelvezu1585
@kelvezu1585 4 года назад
I love the refactoring of codes. I hope you make more of these :)
@himak21
@himak21 2 года назад
Perfect ;) More info in minutes. Great job!!
@TechBuddy006
@TechBuddy006 2 года назад
Thank you soo much as a beginner it helps a lot. ❤️❤️
@Mous28390
@Mous28390 4 года назад
Excellent video and explanation. Thank you for taking the time to make this and share.
@khanalpride
@khanalpride 4 года назад
Nice video. Only concern in my head is, I often stay far from doing ajax request after initial page load. I think its better to send data on first page load, and pass that as props. :)
@Dave-laye
@Dave-laye 4 года назад
excellent, nowadays we talk about livewire and I am sure that the developers (laravel + vue js) will feel more comfortable with the couple laravel + livewire. Can you please do a full tutorial on laravel livewire?
@legendoffeiyouknow709
@legendoffeiyouknow709 3 года назад
I do not recommend Livewire. Reason: * Vue has VueX and Vue Router. In addition, super comprehensive. * Vue's community is much bigger so you can find answers to your questions faster and easier. * Vue allows you to create other projects that don't involve PHP. * Using the API, Vue and Laravel are not related so you can work in a more organized way. * When you have mastered Vue you can quickly learn e.g. React. With Livewire you are limited to only Livewire. * Vue's reactivity is easier and SAFER because when Vue renders the DOM, it doesn't use a back-end like Livewire. Plus it's like 2 times faster. * Learning Vue is easy with only limited JS knowledge! In the end, you need to understand logic. Btw, who says we don't love Vue and Laravel? It's a better duo than Laravel + Livewire!
@Dave-laye
@Dave-laye 3 года назад
@@legendoffeiyouknow709 You can't come to a hasty conclusion and say that you don't recommend the framework. Have you ever used it and do your own comparison yourself? Personally I use Vuejs and Livewire both technologies are powerful and each to its advantage depends on the type of project we have. I think we should give the developers a chance to use these two technologies and make their own comparisons instead of orienting them with our own choices. Livewire is a very good tool for those who use the PHP language most of the time. Not thought of as a JavaScript developer.
@legendoffeiyouknow709
@legendoffeiyouknow709 3 года назад
@@Dave-laye Livewire has no advantage over Vue. For example, if I wanted the ability to upload large video files, the best solution is to chunk the file and then upload it. With Vue, it's easy to send each chunk after the previous chunk is uploaded. Livewire can't do this. With relation to,is that when a user uploads a video, for example, Livewire has no client-side preview. So the user is busy waiting for the file to be uploaded. Suppose it's a large 10GB video and the user has slow internet and later finds out it's the wrong file. Oh well, if only a client-side preview could give the user a good insight before clicking the upload button.... but no, it's Livewire, so not optimal in such situations. This is a small example. And yes, Livewire has benefits, but that's only if you combine it with Apline JS, a JavaScript framework. With Vue, you can combine more handily and optimally. Which, meanwhile, is also more convenient if you work a group. In the end, we want to ensure that users can use the website in the most friendly, convenient, clear and smooth way. With Livewire, you are limited for this, and you will always want more.
@abdonajjar2981
@abdonajjar2981 3 года назад
You are the best laravel video maker i ever seen
@tannercampbell
@tannercampbell 4 года назад
Great video. I’d recommend in Vue component adding a state property in data method so you can you can track progress like is API request loading, is done loading, and make loading animations so user knows. This is helpful especially when using Vue for 3rd party API calls since request take time and you want to show request is getting handled.
@PovilasKorop
@PovilasKorop 4 года назад
Yes at the end of the video I mentioned it as a "homework" to build a "loader" spinning while the action is in progress. Maybe will shoot a separate video on that.
@tannercampbell
@tannercampbell 4 года назад
Povilas Korop oops must of missed that. But yes a video on that specifically when using Vuex state would be a good watch!
@PovilasKorop
@PovilasKorop 4 года назад
@@tannercampbell maybe a silly question but why Vuex? From my understanding and practice, Vuex is mostly for communication between different components, like a global variable, in this case I think it's enough to have one local variable in this one component, no?
@tannercampbell
@tannercampbell 4 года назад
Yes in single component which is fetching data and making any updates that is fine to do that way. I use Vuex as a data store. For example I’ll have a parent vue component which is dynamic table. Inside table I’ll have actions per each row which upon click triggers emitted event to child components that will handle the actions. Where I use Vuex in this example is I’ll dispatch those updates from child component to Vuex that will update the store data. In Vuex store I’ll track the is_loading property so I can know when to re render parent component and show loading animation. In example I’m using Vuex more of way to access and update data in hierarchical level. I hope example helped but I only use Vuex when dealing with components at this level other then that I have them when like you showed in video.
@samikemashiku5054
@samikemashiku5054 3 года назад
hello i have a problem with the variable that we assign data from the api call. when you initialize it as null the v-for shows error "cannot read property of null" but when you initialize it as an empty array like others do some functions in the method throw error that they cannot access data from undefined variable.. the code works fine but how do i resolve that error in the console?
@saravanasai2391
@saravanasai2391 2 года назад
Sir this video is so useful for beginners & how to protect that category routes in api from accessing by others can we use custom middle-ware for it
@miqueiasvinicius9453
@miqueiasvinicius9453 2 года назад
Thanks! You really helped me.
@rahulji6565
@rahulji6565 3 года назад
Issue 1: Until Resubmit it will showing the error. Issue 2: If form is too long it will also not scrolling the page.
@hoshirou_to64p
@hoshirou_to64p 2 года назад
Excuse me sir, I want to ask. on the Controller you use Model, but on my project using Query Builder, can it still be run on Vue later, sir? Thank you in advance, your video is very helpful, sir!
@anumaamir3441
@anumaamir3441 2 года назад
You haven't show how you have displayed list in other component.
@Ramziddin_Rustamovv
@Ramziddin_Rustamovv 2 года назад
Hi , i think this faster way or just clean code ,.
@CheapBurger
@CheapBurger 3 года назад
Hi , my controller is just normal controller , since your tutorial using api/controller i want to ask did my step is good practice if i doing this ? or if i use axios post , i must use api/controller
@jannusdomingo5681
@jannusdomingo5681 2 года назад
Is it asynchronously inserted like AJAX? Btw nice tuts! 🍻
@Dipenparmar12
@Dipenparmar12 4 года назад
I have thing lot for which one can i use react or vue but now i am thinking about only Vue.
@AliHaidar-zw1jx
@AliHaidar-zw1jx Год назад
Could you create how to Convert Graphql api to Restful API and vise versa .
@hammamihassine4
@hammamihassine4 4 года назад
love it keep it up
@MrChickenpoulet
@MrChickenpoulet 4 года назад
hey thanks for the video, is it possible to enable some kind of SSR for our vue component ? without having to install/setup a lot of different things
@blaircfleming
@blaircfleming 4 года назад
Thanks for this video Povilas, I have been enjoying your content immensely and have just enrolled on the "How to Create Laravel API" course to support the channel. One difficulty I am having right now is how to create the Vue.js component for a single category. How do I extract the category id from the url in the format /categories/{category} and provide this to the axios api call in order to display the single category data on the page?
@PovilasKorop
@PovilasKorop 4 года назад
Hi Blair, there are a few ways. One way is to go SPA-way and leave all routing to Vue, with Vue Router, I will talk about it in my next course, coming in a week or two: twitter.com/PovilasKorop/status/1282630612478722048 But if you prefer the Blade-way, then look at component parameters, like with props: vuejs.org/v2/guide/components-props.html
@blaircfleming
@blaircfleming 4 года назад
@@PovilasKorop Thanks Povilas, I tested the Blade-way and it works perfect! I look forward to learning more about the SPA method too, this looks very interesting.
@kennedymwenda3357
@kennedymwenda3357 4 года назад
You are a good teacher. Do you've your courses on Udemy as well?
@oscarcontreras7848
@oscarcontreras7848 4 года назад
Hi, Thanks for the video. I just wonder what was the advantage of using Vue over Blade or in what cases is it useful ?
@PovilasKorop
@PovilasKorop 4 года назад
It's a separate topic to talk about, not for a short comment. But I would say it's for dynamic elements on the website that you want to make dynamic, like reloading some element on other element change or perform some action like submitting the form, without reloading the whole page. It's mostly for web "applications", not for web "sites".
@basharmalsafi2849
@basharmalsafi2849 3 года назад
I really love your videos, you explain everything so well, thank you a lot! Can you create a CRUD Laravel Form: From Blade to Vue.js + API with having relationship dropdown box
@AbdelrahmanMoussaAbuOuf
@AbdelrahmanMoussaAbuOuf 4 года назад
Hi, Great video! Shouldn’t the client error stop the form from posting and thus stop it from hitting the API ?
@PovilasKorop
@PovilasKorop 4 года назад
If I understood your question correctly, yes, you could add the front-end validation and it should happen before hitting the API.
@haziriamin
@haziriamin 3 года назад
please show more laravel + vue.js. thank you.. :)
@iarman8474
@iarman8474 4 года назад
Hello, Can you tell me how can I sum one field on paginated record set? Beacause if you sum on paginated record set it will just sum the current page.
@PovilasKorop
@PovilasKorop 4 года назад
You can't calculate the sum of data from a dataset that doesn't have that data. You need to calculate that sum separately, before pagination, by building a Query Builder: $query = Post::query(); $sum = $query->sum('id'); $posts = $query->paginate(10);
@Supmukesh
@Supmukesh 4 года назад
Which extension you used to populate data into form
@ckmirafss
@ckmirafss 4 года назад
Up
@kid_rz
@kid_rz 4 года назад
filler?
@PovilasKorop
@PovilasKorop 4 года назад
It's called Form Filler
@vidhyaprakash85
@vidhyaprakash85 4 года назад
Povilas Korop link sir
@SquarCoX
@SquarCoX 4 года назад
Awesome video, could you do one using Sanctum to authenticate and one with user roles permissions?
@kid_rz
@kid_rz 4 года назад
thanks. please create more tutorial with vue js or nuxt js. thanks.
@marcinmaj3609
@marcinmaj3609 4 года назад
Great it you show upload file with laravel vue with crop function
@1984jenya
@1984jenya 4 года назад
react + laravel its same way ?
@vidhyaprakash85
@vidhyaprakash85 4 года назад
Can u please give example for dependent drop down country, state and city. We need full example.
@PovilasKorop
@PovilasKorop 4 года назад
Here it is: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-zinkT7IFoCg.html
@vidhyaprakash85
@vidhyaprakash85 4 года назад
Povilas Korop but we need you to do it lively bro
@axeljacobo4453
@axeljacobo4453 4 года назад
hello good afternoon, could you make a trello clone with Laravel and Vue, using Drag and Drop?
@PovilasKorop
@PovilasKorop 4 года назад
It would be quite a big project, I think, but will add to my long list of ideas, maybe someday.
@micheledellamea340
@micheledellamea340 3 года назад
Are you Carlo Ancelotti?
@YassineCoding
@YassineCoding 4 года назад
can you do inertiajs video? i think it's better to give an explanation of this package which is in my opinion is a lifesaver for working with laravel and vuejs i personally use it and like it , it makes vuejs easier and it remove the api's calls pain 100% would recommend anyone to check it out
@PovilasKorop
@PovilasKorop 4 года назад
I don't work with inertia on such a level that I could shoot a video about it. Maybe some time in the future.
@YassineCoding
@YassineCoding 4 года назад
@@PovilasKoropcheck inertiajs pingcrm project and see how it works . and thanks for considering it
@PovilasKorop
@PovilasKorop 4 года назад
@@YassineCoding sorry don't have time, for upcoming two weeks all time for content is already scheduled with all topics. Maybe in the future.
@riffatmazhar5023
@riffatmazhar5023 3 года назад
can you send me the code plz
@bru6626
@bru6626 4 года назад
Thanks Povilas ! Can you do a vue router tutorial ? Thanks in advance!
@PovilasKorop
@PovilasKorop 4 года назад
I'm preparing a course on Vue + Laravel, so routing will be a part of that. Hope to release in a few weeks.
@houssemflutter2722
@houssemflutter2722 4 года назад
Websocket with redis and echo pleas master 😔😔😔
@JohnSmith-zl8rz
@JohnSmith-zl8rz 4 года назад
Is possible NOT use Blade AT ALL in a Laravel project and just use Vue? NO blade!
@rcjuancarlosuwu
@rcjuancarlosuwu 4 года назад
:u use just one file like welcome.blade.php with a div that has the id that will be used. and then u can use just vue js
@paulorobertosallesdossanto6616
@paulorobertosallesdossanto6616 4 года назад
PLEASE ..your explanation must be more slowly....
@AliHaidar-zw1jx
@AliHaidar-zw1jx Год назад
Could you create how to Convert Graphql api to Restful API and vise versa .
@LaravelDaily
@LaravelDaily Год назад
I have a full course about graphql, it may help: laraveldaily.com/course/graphql-laravel
Далее
Should You Switch from Laravel-only to Vue+SPA?
11:45
Вся Правда Про Хазяевов !
41:02
Просмотров 2,1 млн
Todo List App with Laravel and Vue.js
1:00:16
Просмотров 236 тыс.
Livewire or Vue.js: Which to Use When?
12:13
Просмотров 14 тыс.
Is Vue 2 Dead?
10:50
Просмотров 13 тыс.
Build a shopping cart with Laravel Cashier and Vue
55:07
React vs Vue - I Built the Same App in Both Frameworks
1:03:25
Real-Time Chat with Laravel, Vue.js & Pusher
1:09:33
Просмотров 91 тыс.
Laravel Stripe Checkout tutorial | VueJS
23:52
Просмотров 13 тыс.
Vue 3 & Firebase 9 Tutorial (Cloud Firestore)
1:03:47
Просмотров 50 тыс.
Laravel 10 new Features
20:11
Просмотров 7 тыс.
УМНЫЙ СПИЛ ДЕРЕВЬЕВ
0:39
Просмотров 3,5 млн