Services = Business Logic stuff Repositories = Database related stuff Controllers interact with Services. Services interact with Repositories. Repositories interact with a Model and its relational Models if neccesary (one-to-many, many-to-many, etc). Repositories should not access other Repositories, that kind of logic should be done in a Service.
I wish this video came in a couple of weeks earlier. I received a project following that same pattern and it was a little bit hard to understand at first. It was really nice to see your explanation and now I’m more confident in the changes I’m making to this project
I used a Service pattern discussed by Povilas in one of the projects I work on, it was really helpful! Needed to duplicate some functionality on different pages.
I remember to avoid TypeHint REQUEST in service via Dependency Injection. Instead just pass Request Array. It is useful in TESTs also. Respect from Pakistan 🇵🇰
What i personally prefer that in service you have specified methods iwht actual parameters you want to call. So instead of passing request or some general array you just provide like int, strings etc stuff and other arrays, like only what's needed for a method.
Thanks a lot for sharing examples regarding Services and Repositories, I hope you keep posting more of it because it's really helpful. The only thing that seems off to me is the idea of passing the request to the service. I've seen it in cases even reaching to the repository and I don't believe it's a good practice. It makes quite hard to reuse these methods since you don't know which fields the method uses unless you read it thoroughly
The author of the video is fool. This kills the whole point of using the services/usecases. We will not be able to call such service from the API, console application or queue system.
@@thamibn Are you joking? What's the matter what was in the other videos? In this video he uses function auth()->user(). And now the question, what if he calls this service from console? Everything will break, and how i said above this kills the whole point of using services.
@@anmaner4822 he did not use it his not the one who wrote the code, basically in this video he was showing us how services worka or helps with code readability, he was not by any means trying to fix the code inside those services, if you can check there are many wrong things on those services he demonstrated but the video was not about fixing them instead on how to use them Nd how they help. On the other video he clearly thought how to write service classes, and he not to use $request since it won't be accessible when the service is being called on tests,commands etc... I do agree that the service classes used on the video where poorly coded, my point is don't call him fool cause is not his code and he was not fixing them service classes on this video.
Really interesting and useful, since Service/Repository is a common pattern also used in other languages, for instance in Java, to build more structured modules (and to make controllers or jobs or whatever much shorter!). It’s a very important topic.
You mentioned at the end ”To off load your controllers and make controllers shorter” does it mean better performance in controllers? And thats why we use Service? Or is it only for structure and readability?
I am recently learning different design pattern of php. I would be glad to know different design patterns that can be used with laravel beside services.
Thank u for the video,Is this good habit making two new instance of a class as seen as 3:15 second of video with Booking class?.May it perform for speed or cpu ?.
Wonder if there are any tests for those services in the examples and if services that have tests are written "better" than the ones that don't have tests.
hello sir .i install jetstream and then i want to extend layouts.app in another file but layouts.app file contain $header and $slot ,so it give $header is not defined or same for $slot.how can then i extend layout.app. im using laravel 8 with jetstream livewire
Hello Dear! Please tell me which framework vue or livewire is good to use with laravel. Should we use vue if our site is too much reactive or livewire would be a good choice in case site is too much reactive.
I quite like Jobs, but not for CRUD operations themselves, but rather AFTER CRUD operation. So, like User::create() and then dispatch a Job to send an email.
I have a full separate course: laraveldaily.teachable.com/p/datatables-in-laravel Also, search the channel for "datatables", you will find quite a lot of videos.
Hi Povilas, thanks for the great video with Laravel services patterns reviewal! Just wanted to ask you, have you some preferable PHP and Laravel packages very useful for building API for Laravel based SPA? I'm most interested with the secure authentication/authorisation, flexible roles management, message driven services, multi-tenancy. Probably some of them are already included in the scope of QuickAdminPanel stack. Could you please make a quick review based on your experience, or share some practical advices? Thanks a lot and please don't stop posting new streams! Cheers.
You guys have good team why don't you make an ecommerce platform and sale its components just like other doing etc opencart? I don't see any good ecommerce platform in laravel with good documentations. You can easily build opencart like with your capabilities
It would cost too much. And personally, I don't believe in financial success, as there are already ecommerce platforms on Laravel, but none of them seemed to get traction.
Services = Business Logic stuff
Repositories = Database related stuff
Controllers interact with Services.
Services interact with Repositories.
Repositories interact with a Model and its relational Models if neccesary (one-to-many, many-to-many, etc).
Repositories should not access other Repositories, that kind of logic should be done in a Service.
so i may not call a repository in a controller? would be right: controller -> service -> repo?
Thanks for mentioning my code in 2nd example. And it's not a fully done project yet. I am still doing that project.
Man your contents are getting richer. 😀
I wish this video came in a couple of weeks earlier. I received a project following that same pattern and it was a little bit hard to understand at first.
It was really nice to see your explanation and now I’m more confident in the changes I’m making to this project
Awesome stuff, I always get a lot of stuff from your videos.
I used a Service pattern discussed by Povilas in one of the projects I work on, it was really helpful! Needed to duplicate some functionality on different pages.
I remember to avoid TypeHint REQUEST in service via Dependency Injection. Instead just pass Request Array.
It is useful in TESTs also.
Respect from Pakistan 🇵🇰
Learned that the hard way.
What i personally prefer that in service you have specified methods iwht actual parameters you want to call. So instead of passing request or some general array you just provide like int, strings etc stuff and other arrays, like only what's needed for a method.
Thanks a lot for sharing examples regarding Services and Repositories, I hope you keep posting more of it because it's really helpful.
The only thing that seems off to me is the idea of passing the request to the service. I've seen it in cases even reaching to the repository and I don't believe it's a good practice. It makes quite hard to reuse these methods since you don't know which fields the method uses unless you read it thoroughly
The author of the video is fool. This kills the whole point of using the services/usecases. We will not be able to call such service from the API, console application or queue system.
@@anmaner4822 he did a video about not using request on services, so don't call him a fool, cause he did not even say it was good in this video.
@@thamibn Are you joking? What's the matter what was in the other videos? In this video he uses function auth()->user(). And now the question, what if he calls this service from console? Everything will break, and how i said above this kills the whole point of using services.
@@anmaner4822 he did not use it his not the one who wrote the code, basically in this video he was showing us how services worka or helps with code readability, he was not by any means trying to fix the code inside those services, if you can check there are many wrong things on those services he demonstrated but the video was not about fixing them instead on how to use them Nd how they help.
On the other video he clearly thought how to write service classes, and he not to use $request since it won't be accessible when the service is being called on tests,commands etc...
I do agree that the service classes used on the video where poorly coded, my point is don't call him fool cause is not his code and he was not fixing them service classes on this video.
Really interesting and useful, since Service/Repository is a common pattern also used in other languages, for instance in Java, to build more structured modules (and to make controllers or jobs or whatever much shorter!).
It’s a very important topic.
You are really superman ❤️🇸🇩 thank you For the grateful lite tutorials. u are helpful please go on don't stop
Thank you for the feedback 👍
When dealing with DB transaction, It should be done in controller or in a service? The service should be throw exceptions and the controller catch it?
Please make a video about PORTO pattern (implemented on apiato project) thanks! Most used architectual patterns for large laravel projects
Respect from 🇯🇲
You mentioned at the end ”To off load your controllers and make controllers shorter” does it mean better performance in controllers? And thats why we use Service? Or is it only for structure and readability?
It's for structure and readability
I am recently learning different design pattern of php. I would be glad to know different design patterns that can be used with laravel beside services.
I discuss a lot of them in my course: laraveldaily.teachable.com/p/how-to-structure-laravel-project
Thank u for the video,Is this good habit making two new instance of a class as seen as 3:15 second of video with Booking class?.May it perform for speed or cpu ?.
Wonder if there are any tests for those services in the examples and if services that have tests are written "better" than the ones that don't have tests.
hello sir .i install jetstream and then i want to extend layouts.app in another file but layouts.app file contain $header and $slot ,so it give $header is not defined or same for $slot.how can then i extend layout.app.
im using laravel 8 with jetstream livewire
Super! Very useful video.
I think the service can catch an exception if the purpose is for logging or debugging
Could SpliCostService be a Trait as well?
Hello Dear! Please tell me which framework vue or livewire is good to use with laravel. Should we use vue if our site is too much reactive or livewire would be a good choice in case site is too much reactive.
Very informative!
@3:27 IMO policy inside the StoreBookingRequest would be better to implement the same functionality (availabilityCheck)
Wow this is what I am waiting for
Can you make a vid that explain how to structure your payment services (Paypal, Stripe, local banks ..etc) and use it with a clean code?
That would be a full 5-hour course. Maybe someday I will have enough time for it.
This approach would be nice with Domain Driven Design
how to remove dublicate value from an array while using foreach directive loop in laravel?
Try converting to collection and use unique() laravel.com/docs/8.x/collections#method-unique
@@LaravelDaily thanks you sir, thats working
How can I switch between Paypal / Card Payment / Anything if the binding is with the service provider, if the user has a choice when paying.
Yes, valid question, that example code wouldn't work for your scenario.
You could pass the payment method in request and check that payment in service provider and bind the class according to request payment variable.
Nice stuff
First of all, thank you so much for all your work! What are your thoughts on using Jobs for all CRUD (except Read part) operations?
I quite like Jobs, but not for CRUD operations themselves, but rather AFTER CRUD operation. So, like User::create() and then dispatch a Job to send an email.
So this repository pattern has nothing to do with Symfony repositories?
😂😂😂
@@adebajooluwaseyi2124 what's funny?
Respect from 🇹🇿Tz
Please review DataTables and why do we need it :)
I have a full separate course: laraveldaily.teachable.com/p/datatables-in-laravel
Also, search the channel for "datatables", you will find quite a lot of videos.
Services vs Actions, or is the pattern essentially the same?
I will have a separate video on Actions, in a few days.
Hi Povilas, thanks for the great video with Laravel services patterns reviewal! Just wanted to ask you, have you some preferable PHP and Laravel packages very useful for building API for Laravel based SPA? I'm most interested with the secure authentication/authorisation, flexible roles management, message driven services, multi-tenancy. Probably some of them are already included in the scope of QuickAdminPanel stack. Could you please make a quick review based on your experience, or share some practical advices? Thanks a lot and please don't stop posting new streams! Cheers.
Not sure if there are "best practices", I guess I would list Laravel Sanctum and Spatie Permissions.
You guys have good team why don't you make an ecommerce platform and sale its components just like other doing etc opencart? I don't see any good ecommerce platform in laravel with good documentations. You can easily build opencart like with your capabilities
It would cost too much. And personally, I don't believe in financial success, as there are already ecommerce platforms on Laravel, but none of them seemed to get traction.
hi sir, I had learn a lot from your videos, and even started exploring many concept. sir can you give me way to contact you. need your consultants .
wow terima kasih
Please make laravel from scratch for beginners 🙏🙏🙏🙏🙏
Done: laraveldaily.teachable.com/p/laravel-for-beginners-your-first-project
Respect from Ukraine 🇺🇦
first view first like