I was looking for channel like this for so long, till now I haven't found a dev which is advanced and also shares his knowledge of architecture beyond controllers
Beyond pro level, watched that video before going to sleep. Now its 4:44 am I'm still watching it again and again , learning every topic that showed! Thanks man!
Рік тому+2
This was amazing. I never had seem so soft refactoring Thanks and again: you're the best
2 роки тому+1
idk, youtube recommends these with some delay :D I just started doing the same thing with my huge controllers at work, and now I see this in my feed :D How cool :)
That's insane man, from many lines of codes to, two lines of code. That's incredible, thanks much for sharing this with us...i'm new in Laravel and this is my dream to code like this.
Thanks a lot for making these kind of videos. Recently discovered your channel and slowly watching your videos. It's amazing how you make subjects that were unknown to me very easily understandable and right away I can see the use cases for my own projects because you show real-life examples. An amazing channel and huge compliments to you as a teacher.
Can be considered but if you declared a fillable array on the model it won't assign anything other than those values declard in the model. But from readability you're right
@Lukas Korbitsch I know that, assume you have model Customer with fillable fields: name, email, status, and some user allowed to update ONLY the status of customer (set active or inactive), in that form user could inject input name or email that Shouldn't updated
Reasonable for fat actions. If applied for small ones, now instead of quickly seeing all functionality at single look , you will have to navigate +5 or more extra files.
i'm grateful that we have teacher like you, when i'm doing programming i study core php for 1year and i hate laravel so much but when i find job as programmer they required me to study laravel (the framework most i hated) i hate laravel because im also security researcher and i know laravel have zero day exploit but i have no choice i need to study laravel and one day youtube suggest your channel now im fully understand the laravel and what is advantages of laravel and now im started to love it thanks man! you save me to find awesome job now im junior developer i'm already 3months in job as junior programmer/developer but i think my knowledge is enough as senior developer thank you very much bro. but i have request im hard to understand and refactor the Policy/authorization the most important part of developing app, please help me to understand newbie like me the how to use policy and add custom method using authorizeResource() and resourceAbilityMap() Thanks bro
Amazing video! I was searching for something like this for years. I always disliked most tutorials polluting the controller with "ifs" and "for" and validations.
Thanks for the great tutorial. But I think it can sometimes make other developers worried if they are not following the same path. For example now the controller is very tiny. They are debugging an issue, they see that some data is being updated, but where is it? I have seen the observers for the first time here. Same may be the case with many people. This is indeed handy and keeps the code clean and short, but can sometimes create confusion. When it comes to FormRequests, yeah they are common, so if a developer does not find validation in Controller, they wiill directly think that yeah it can be in the FormRequest. So I am in 50 50 for using those observers and the like stuff. they can complicate things a little bit.
What is the difference between observers and events? I would rather use event over observer because code in controller tells me what happens. It's kinda hidden when you do it with observers. What do you think?
Good point, I agree with you. Another thing is that observers are mostly for MODEL observing, specifically for created/updated etc, and events are broader and can be used anywhere.
Basically in simple terms you can call Observers as Model Hooks where we can hook some code before or after Create, Update, Delete kind of stuff. Where as events are like when something happened. So basically I would put the Admin Notifiations code in Events where we could listen for more stuff. So I would delegate my code here. Eg: PostPublished Jobs on the other hand is like before something happens Eg: PublishPost There lies a thin line which coud confuse most of the developers but over the time you will get to know after using in much of the projects.
The MVC concept is to put all the logic functions model (such word counting), the controller to interact between the model and the view. This is my basic understanding of MVC.
Great video, I would also recommend using collection methods with anonymous function instead of foreach, for eg : $posts->each(function ($post) use ($otherStuff) { //Do here } You can also use &$parameter for sending your variable by reference and it will be saved after anonymous function, similar to pointer in C/C++
sir your videos are too gud and helpful , i even started your free course for beginners in laravel, and i m waiting if you will uplaod any course realted to vue and laravel api
Although the code is clean there is something that bugging me and that is that it’s not apparent all these extra functionalities which makes debugging much harder. And I don’t mean in Laravel specifically. Unless some kind of mechanism has been set up like let’s say a plug-in system you are going to pull your hair out in a real world much complicated project
@@davidbasil3161 In general comments should be used when there is a complicated piece of code otherwise code should be self explanatory through the name of the methods and attributes IMO. Also in my experience if you have a code base with lots of comments it's most likely that people won't pay much attention to them. If there are some comments here and there it's much more alarming to fellow devs when they see these comments
2 роки тому
@@SaiyanJin85 tru. In years my code became so semantic, so I can send a screenshot to my project owner who has no clue about programming asking him if the business logic is okay, and he is able to validate it :D
i am using maatwebsite excel package, is there a way to import data and check validation on some specific fields, if any record fails to match validation, record the whole rows in a report excel file with the error message or red color in that field text which are not proper (the reason why validation failed) and then finally after full import have and option to download error excel file. So that we can correct the fields and upload that file again.Do you have any tutorial like this. I will be highly thankful if you guide me how to do this, i have tried to read the maatwebsite excel package documentation, but it is not very much clear to me.
one question, if you are new to this kind of project how do you know, that there is a service and an observer if you don't reference it in the controller?
Well, a lot of things may be outside of controllers, it's not only in the controllers you should look, you need to research all folders to understand how it is structured.
@@PovilasKorop yes, im still a beginner in laravel, but what it is very practical to me is to follow the view controller model, clearly defined in the routes/web. I hope to get more pro soon, :)
hi guys, great material here. I need to make a functionality to take a csv as a request and update multiple tables, how would be the correct way to afront this in laravel,?? (-the validation of the csv -creating records in many database and sending a response )
There's no one "correct" way. It depends on the complexity of your CSV, what kind of validation you need, and what you need to do after validation errors or after creating records. On each of the steps, there may be an error and you need to handle it in your way. You won't get such an answer in a simple UA-cam comment.
Maybe you're getting that because you're doing GET request instead of POST? In CRUD-based controllers, it's pretty convenient to pass model object, and avoid one more find() in controller, so it makes controller shorter and more readable. Read about model binding here in official docs: laravel.com/docs/5.7/routing#route-model-binding
hello, lately I've been watching your videos a lot. many good things i've learn from you. thank you so much. but I have a question how to prevent race conditions when using observers or event listeners or services do you use lockForUpdate method? please make video about lockForUpdate, rollback related with observers, event listener, and services. thank you.
This would be a great addition to QuickAdminPanel. Being able to export a solution as a module and add it to a project would help continuous development.
No, $request->all() doesn't perform validation. Validation is in whatever FormRequest class you pass to the store() as parameter. Read more about FormRequest classes: laravel.com/docs/master/validation#form-request-validation
In a 15-minute video, I learned more than in 2 hours lessons! Thank you very much!
definitely
Agreed. I have been learning Laravel for 2 days and this is super helpful.
agreed
I was looking for channel like this for so long, till now I haven't found a dev which is advanced and also shares his knowledge of architecture beyond controllers
This is the best Laravel video I've ever seen.
This is the best 15 minutes video I have ever watched. Amazing tips.
This video is 100% informative and 80% eyes hurting.
Beyond pro level, watched that video before going to sleep. Now its 4:44 am I'm still watching it again and again , learning every topic that showed!
Thanks man!
This was amazing. I never had seem so soft refactoring
Thanks and again: you're the best
idk, youtube recommends these with some delay :D I just started doing the same thing with my huge controllers at work, and now I see this in my feed :D How cool :)
Phenomenal! I have a good 3-4 hours of reading and experimentation to do after watching this.
In a 15 min video, I learned more than in 2 hours lessons! You're the best, Thank you very much!
That's insane man, from many lines of codes to, two lines of code. That's incredible, thanks much for sharing this with us...i'm new in Laravel and this is my dream to code like this.
This video has cleared so many concepts. not necessarily we apply all of these but so much information and practically displayed. Awesome Sir !
How could I be so wrong for so long?
Thanks for this...this is gold!
Wow!!! The best refactory that I saw! Congrats!
Brilliant... Looking forward to more of such refactoring videos.
Thanks a lot for making these kind of videos. Recently discovered your channel and slowly watching your videos. It's amazing how you make subjects that were unknown to me very easily understandable and right away I can see the use cases for my own projects because you show real-life examples. An amazing channel and huge compliments to you as a teacher.
Thank u so much sir for giving us your precious time . I started following you and you are so good.
Also it will be better to user request->validated() instead of request->all() to insert the validated fields only
Can be considered but if you declared a fillable array on the model it won't assign anything other than those values declard in the model. But from readability you're right
Yes, Somebody could inject html input and randomly guessing the another input that shouldn't update in that form (included in fillable variable)
@@AnggaAriWijaya laravel will only fill values which (if) are specified in the fillables array on the model
@Lukas Korbitsch I know that, assume you have model Customer with fillable fields: name, email, status, and some user allowed to update ONLY the status of customer (set active or inactive), in that form user could inject input name or email that Shouldn't updated
@@AnggaAriWijaya ah I see where you going yeah you're right. But in this scenario I wouldnt build it like thst
Reasonable for fat actions. If applied for small ones, now instead of quickly seeing all functionality at single look , you will have to navigate +5 or more extra files.
Exactly, instead of 20 lines, now hundreds in many files, without any comment in controller.
Wow this was so well done. Short and so much informative. Thanks
This is one of the best laravel lessons on youtube
Thanks for explaining, was searching for this kind of video for a while. It all makes a bit more sense.
i'm grateful that we have teacher like you, when i'm doing programming i study core php for 1year and i hate laravel so much but when i find job as programmer they required me to study laravel (the framework most i hated) i hate laravel because im also security researcher and i know laravel have zero day exploit but i have no choice i need to study laravel and one day youtube suggest your channel now im fully understand the laravel and what is advantages of laravel and now im started to love it thanks man! you save me to find awesome job now im junior developer i'm already 3months in job as junior programmer/developer but i think my knowledge is enough as senior developer thank you very much bro.
but i have request im hard to understand and refactor the Policy/authorization the most important part of developing app, please help me to understand newbie like me the how to use policy and add custom method using authorizeResource() and resourceAbilityMap()
Thanks bro
I'm sorry but what do you mean by laravel has zero day exploit?
and doesn't the exact same thing apply to every major open source language/framework ?
Amazing video! I was searching for something like this for years. I always disliked most tutorials polluting the controller with "ifs" and "for" and validations.
Thanks for the great tutorial. But I think it can sometimes make other developers worried if they are not following the same path. For example now the controller is very tiny. They are debugging an issue, they see that some data is being updated, but where is it? I have seen the observers for the first time here. Same may be the case with many people. This is indeed handy and keeps the code clean and short, but can sometimes create confusion. When it comes to FormRequests, yeah they are common, so if a developer does not find validation in Controller, they wiill directly think that yeah it can be in the FormRequest. So I am in 50 50 for using those observers and the like stuff. they can complicate things a little bit.
a good solution would be to add a comment to inform the developers that that specific action is handled in an observer
@@MahmoudMohsab yes you are right.
@@MahmoudMohsab Thats exactly what I was asked to do when I submitted PR .
Its realy a nice and comprehensive demonstration, learnt alot
What is the difference between observers and events? I would rather use event over observer because code in controller tells me what happens. It's kinda hidden when you do it with observers. What do you think?
Good point, I agree with you. Another thing is that observers are mostly for MODEL observing, specifically for created/updated etc, and events are broader and can be used anywhere.
Good points of view, guys. I agree with all you said.
Basically in simple terms you can call Observers as Model Hooks where we can hook some code before or after Create, Update, Delete kind of stuff.
Where as events are like when something happened. So basically I would put the Admin Notifiations code in Events where we could listen for more stuff. So I would delegate my code here. Eg: PostPublished
Jobs on the other hand is like before something happens Eg: PublishPost
There lies a thin line which coud confuse most of the developers but over the time you will get to know after using in much of the projects.
The MVC concept is to put all the logic functions model (such word counting), the controller to interact between the model and the view. This is my basic understanding of MVC.
very good, I was impressed, I will take your course
This was insanely helpful, thanks so much. Laravel blows me away everyday
the best example you will see it the world!
Thank you ..
OMG! now it is two lines of code. Amazing!
great explanation! PS. As you also showed only([...]), you could've also used $request->validated() instead of ->all().
Liked this video? I have many more: subscribe to my 30+ Laravel courses laraveldaily.com/courses
Great video, I would also recommend using collection methods with anonymous function instead of foreach, for eg :
$posts->each(function ($post) use ($otherStuff) {
//Do here
}
You can also use &$parameter for sending your variable by reference and it will be saved after anonymous function, similar to pointer in C/C++
Thanks a lot! Keep doing examples like this, really useful for me
What's the use case between a service and adding a method like that to the Post model, for instance?
Congratulations! You really bring valuable content in your videos!
I really appreciate your work. kudos
Great example and nice explanation
Hope to see more Live Coding session from your channel ..
what if I want to update my post in other place but without sending the email?
Perfect! Great video, I learned a lot.
sir your videos are too gud and helpful , i even started your free course for beginners in laravel, and i m waiting if you will uplaod any course realted to vue and laravel api
This was really helpful! Thank you.
can i use a custom method name on my controller and have my observer listen to that method
Потрясающе! Спасибо огромное :))))
how to use redirectAction here?
Although the code is clean there is something that bugging me and that is that it’s not apparent all these extra functionalities which makes debugging much harder. And I don’t mean in Laravel specifically. Unless some kind of mechanism has been set up like let’s say a plug-in system you are going to pull your hair out in a real world much complicated project
@@davidbasil3161 In general comments should be used when there is a complicated piece of code otherwise code should be self explanatory through the name of the methods and attributes IMO. Also in my experience if you have a code base with lots of comments it's most likely that people won't pay much attention to them. If there are some comments here and there it's much more alarming to fellow devs when they see these comments
@@SaiyanJin85 tru. In years my code became so semantic, so I can send a screenshot to my project owner who has no clue about programming asking him if the business logic is okay, and he is able to validate it :D
the best video! You're the best, man !
How to check for email and sms success and failure, whether its sent or failed throwing exceptions
I don’t normally follow without good cause. But I’m following you.
well, does it work for all the version ?
You couldn't call observer in your postController, so how update method knows about observer?
in 41st line of the original code, there is $words_count(), which i think should be $words_count. is it?
i am using maatwebsite excel package, is there a way to import data and check validation on some specific fields, if any record fails to match validation, record the whole rows in a report excel file with the error message or red color in that field text which are not proper (the reason why validation failed) and then finally after full import have and option to download error excel file. So that we can correct the fields and upload that file again.Do you have any tutorial like this.
I will be highly thankful if you guide me how to do this, i have tried to read the maatwebsite excel package documentation, but it is not very much clear to me.
one question, if you are new to this kind of project how do you know, that there is a service and an observer if you don't reference it in the controller?
Well, a lot of things may be outside of controllers, it's not only in the controllers you should look, you need to research all folders to understand how it is structured.
@@PovilasKorop yes, im still a beginner in laravel, but what it is very practical to me is to follow the view controller model, clearly defined in the routes/web. I hope to get more pro soon, :)
@@Paltibenlaish this isnt specific to laravel btw - other frameworks even languages you should aim to do coding like this..
You have great knowledge of Laravel..
NOtifications can be Queueable, no need to make Job.
Exactly
Thanks man. Very good examples. Make more videos please...
its great video and u explain so simply thanks man
At 3:22, why not use request->validated() to pass only those fields which are being validated through request.
this is an old video, he uses validated() nowadays because of obvious security flaws
Great Tutorial @Povilas!
Awesome tutorial 🙏 Thanks a lot man!
why start observer on app service provider instead of on post class?
Just one of the options, personal preference
omg this video so amazing tks you so much for share your knowledge
hi guys, great material here.
I need to make a functionality to take a csv as a request and update multiple tables,
how would be the correct way to afront this in laravel,??
(-the validation of the csv -creating records in many database and sending a response )
There's no one "correct" way. It depends on the complexity of your CSV, what kind of validation you need, and what you need to do after validation errors or after creating records. On each of the steps, there may be an error and you need to handle it in your way. You won't get such an answer in a simple UA-cam comment.
@@PovilasKorop haha, right, thank you for your answer, really looking forward for more of your amazing videos :)
Nice work !😊
Thanks. It's a great tutorial!
Awesome, very helpful
Thanks as always.
Thanks for this video! It's so helpful!
Thanks for your effort
I like the way you do it!
this video make me understand how to refactor my controller
Awesome video! Thank you!
magic method __LaravelBusiness thank you :-)
WOW. Grate Tutorial ❤
Why you dont use post_id ? I get response methodNotAllowedHttpException with this code update(Post $post).
Maybe you're getting that because you're doing GET request instead of POST? In CRUD-based controllers, it's pretty convenient to pass model object, and avoid one more find() in controller, so it makes controller shorter and more readable. Read about model binding here in official docs: laravel.com/docs/5.7/routing#route-model-binding
hello, lately I've been watching your videos a lot. many good things i've learn from you. thank you so much.
but I have a question how to prevent race conditions when using observers or event listeners or services
do you use lockForUpdate method? please make video about lockForUpdate, rollback related with observers, event listener, and services. thank you.
Shouldn’t it be $request->validated() instead of $request->all() ??
nice teaching.
That was pretty cool ❤️❤️❤️
I think it was not necessary to use the Job with the notification, You can implement the ShoulQueue interface and Laravel takes care of the rest.
This would be a great addition to QuickAdminPanel. Being able to export a solution as a module and add it to a project would help continuous development.
It's almost impossible to export something as a module that would fit into any project, we just can't build modules that flexible, sorry.
@@PovilasKorop It's already a great tool and your content is extremely helpful. Thank you for your answer.
give me this code, is it in git?
man,you are awesome!!!!!
Great stuff, It would be better if you have automated tests and for each modification you do, run the tests.
Yes, it would be better.
Outstanding!
Great tutorial
Thank you so much. I learned lot
Nice and usefull tutoriall. Please some more info about clean and nice code. Does $request->all() automatically perform the validation??
No, $request->all() doesn't perform validation. Validation is in whatever FormRequest class you pass to the store() as parameter. Read more about FormRequest classes: laravel.com/docs/master/validation#form-request-validation
Wonderfull job!
Thank you so much very help full
Thank you very much!
Thank you! Great example I do the same in my codebase!
Hi and thanks for this video.
It's great. Thanks a lot
Oh my god ... amazing tutorial
You are great
thanks alot
Thank you.