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 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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.