Laravel Services and Repositories: 3 Example Projects

  Рет қаралды 38,348

Laravel Daily

Laravel Daily

Күн бұрын

Service classes in Laravel is one of the most misunderstood concepts because developers use them in a very different way. Let's take a look at three examples.
SendPortal repository: github.com/mettle/sendportal-...
- - - - -
Support the channel by checking out our products:
- Try our Laravel QuickAdminPanel: bit.ly/quickadminpanel
- Enroll in my Laravel courses: laraveldaily.teachable.com
- Purchase my Livewire Kit: livewirekit.com
- Subscribe to my weekly newsletter: bit.ly/laravel-newsletter

Пікірлер: 64
@robertoflores2078
@robertoflores2078 3 жыл бұрын
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.
@TIAGO543211
@TIAGO543211 2 жыл бұрын
so i may not call a repository in a controller? would be right: controller -> service -> repo?
@gustavoaeidt
@gustavoaeidt 3 жыл бұрын
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
@cultureofnepal2024
@cultureofnepal2024 3 жыл бұрын
Thanks for mentioning my code in 2nd example. And it's not a fully done project yet. I am still doing that project.
@phil86_
@phil86_ 3 жыл бұрын
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.
@SowrenSen
@SowrenSen 3 жыл бұрын
Man your contents are getting richer. 😀
@popplestones886
@popplestones886 3 жыл бұрын
Awesome stuff, I always get a lot of stuff from your videos.
@ujjal147
@ujjal147 3 жыл бұрын
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.
@nabeelyousafpasha
@nabeelyousafpasha 3 жыл бұрын
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 🇵🇰
@MaizerGomes
@MaizerGomes 3 жыл бұрын
Learned that the hard way.
@Jurigag
@Jurigag 3 жыл бұрын
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.
@MegaOsama99
@MegaOsama99 3 жыл бұрын
You are really superman ❤️🇸🇩 thank you For the grateful lite tutorials. u are helpful please go on don't stop
@nevesparrottino4394
@nevesparrottino4394 3 жыл бұрын
Thank you for the feedback 👍
@jjhehe5747
@jjhehe5747 3 жыл бұрын
Very informative!
@pvaitonis
@pvaitonis 3 жыл бұрын
Super! Very useful video.
@kevinpallado9638
@kevinpallado9638 3 жыл бұрын
Wow this is what I am waiting for
@JoseVasquez-vy8yf
@JoseVasquez-vy8yf 3 жыл бұрын
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
@anmaner4822
@anmaner4822 3 жыл бұрын
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
@thamibn 3 жыл бұрын
@@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.
@anmaner4822
@anmaner4822 3 жыл бұрын
​@@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.
@thamibn
@thamibn 3 жыл бұрын
@@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.
@joaoprizal8936
@joaoprizal8936 3 жыл бұрын
Please make a video about PORTO pattern (implemented on apiato project) thanks! Most used architectual patterns for large laravel projects
@al-aminhamadi9451
@al-aminhamadi9451 3 жыл бұрын
Nice stuff
@alexrusin
@alexrusin 3 жыл бұрын
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.
@MrKederli
@MrKederli 3 жыл бұрын
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 ?.
@jasonennis4905
@jasonennis4905 3 жыл бұрын
Respect from 🇯🇲
@jannatulnayeem7289
@jannatulnayeem7289 3 жыл бұрын
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.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I discuss a lot of them in my course: laraveldaily.teachable.com/p/how-to-structure-laravel-project
@uzairsharif7568
@uzairsharif7568 3 жыл бұрын
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.
@ruslanvoroshchukowlookitlt245
@ruslanvoroshchukowlookitlt245 3 жыл бұрын
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.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Not sure if there are "best practices", I guess I would list Laravel Sanctum and Spatie Permissions.
@dApoTB
@dApoTB 3 жыл бұрын
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?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
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.
@atatopatato
@atatopatato 3 жыл бұрын
@3:27 IMO policy inside the StoreBookingRequest would be better to implement the same functionality (availabilityCheck)
@risoledoce
@risoledoce 2 жыл бұрын
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?
@ahmadrio
@ahmadrio 3 жыл бұрын
wow terima kasih
@shahidjutt5656
@shahidjutt5656 3 жыл бұрын
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
@joshbarros1995
@joshbarros1995 2 жыл бұрын
This approach would be nice with Domain Driven Design
@balle19941
@balle19941 3 жыл бұрын
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?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
It's for structure and readability
@manishchourasiya3988
@manishchourasiya3988 3 жыл бұрын
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 .
@amanikafonogo9695
@amanikafonogo9695 3 жыл бұрын
Respect from 🇹🇿Tz
@mohamedhaj5143
@mohamedhaj5143 3 жыл бұрын
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?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
That would be a full 5-hour course. Maybe someday I will have enough time for it.
@Diego-eb9we
@Diego-eb9we 2 жыл бұрын
Could SpliCostService be a Trait as well?
@abdulbasitsalah2918
@abdulbasitsalah2918 3 жыл бұрын
how to remove dublicate value from an array while using foreach directive loop in laravel?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Try converting to collection and use unique() laravel.com/docs/8.x/collections#method-unique
@abdulbasitsalah2918
@abdulbasitsalah2918 3 жыл бұрын
@@LaravelDaily thanks you sir, thats working
@danorex9100
@danorex9100 3 жыл бұрын
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.
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Yes, valid question, that example code wouldn't work for your scenario.
@cultureofnepal2024
@cultureofnepal2024 3 жыл бұрын
You could pass the payment method in request and check that payment in service provider and bind the class according to request payment variable.
@raimonds.L
@raimonds.L 3 жыл бұрын
Please review DataTables and why do we need it :)
@LaravelDaily
@LaravelDaily 3 жыл бұрын
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.
@1mr4n4li
@1mr4n4li 3 жыл бұрын
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
@LaravelDaily
@LaravelDaily 3 жыл бұрын
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.
@guillermocava3568
@guillermocava3568 3 жыл бұрын
Services vs Actions, or is the pattern essentially the same?
@LaravelDaily
@LaravelDaily 3 жыл бұрын
I will have a separate video on Actions, in a few days.
@angelogrieco
@angelogrieco 3 жыл бұрын
So this repository pattern has nothing to do with Symfony repositories?
@adebajooluwaseyi2124
@adebajooluwaseyi2124 3 жыл бұрын
😂😂😂
@angelogrieco
@angelogrieco 3 жыл бұрын
@@adebajooluwaseyi2124 what's funny?
@safara_umarov
@safara_umarov 3 жыл бұрын
Please make laravel from scratch for beginners 🙏🙏🙏🙏🙏
@LaravelDaily
@LaravelDaily 3 жыл бұрын
Done: laraveldaily.teachable.com/p/laravel-for-beginners-your-first-project
@abhishekpakhare7682
@abhishekpakhare7682 3 жыл бұрын
first view first like
@popelyshyn
@popelyshyn 3 жыл бұрын
Respect from Ukraine 🇺🇦
Junior Code Review: Laravel Routes, Middleware, Validation and more
19:57
Laravel: Why Observers and Event Listeners are "Risky"
8:45
Laravel Daily
Рет қаралды 26 М.
Mama vs Son vs Daddy 😭🤣
00:13
DADDYSON SHOW
Рет қаралды 25 МЛН
MISS CIRCLE STUDENTS BULLY ME!
00:12
Andreas Eskander
Рет қаралды 12 МЛН
Why use Type and not Interface in TypeScript
14:12
ByteGrad
Рет қаралды 197 М.
Laravel Service Providers: All You Need to Know
13:13
Laravel Daily
Рет қаралды 64 М.
18 Laravel/PHP Tips in 10 Minutes: June 2024
10:41
Laravel Daily
Рет қаралды 9 М.
Laravel: Repository Pattern in practice
27:13
Przemysław Przyłucki
Рет қаралды 10 М.
I Reviewed Your Beginner React Code
12:36
Josh tried coding
Рет қаралды 98 М.
Laravel Pivot Tables: Simple to Advanced Many-to-Many
12:24
Laravel Daily
Рет қаралды 119 М.
Master Golang with Interfaces
21:54
Kantan Coding
Рет қаралды 9 М.
9 Tips for Shorter Laravel Code
10:16
Laravel Daily
Рет қаралды 61 М.
CAA Conversion kit at ZAHAL 🎯
0:14
Zahal Youtube
Рет қаралды 57 МЛН
Платье для богинь на свадьбу
1:00
Настя Бруно
Рет қаралды 3,6 МЛН
I lost my kitten on the street😭 #cat #cats
0:32
Prince Tom
Рет қаралды 160 МЛН
Amazing! Taiwanese Giant Watermelon Juice - Fruit Cutting Skills
0:47
Foodie Camp 푸디캠프
Рет қаралды 61 МЛН
Заботьтесь о любимых❤️🫶🏾 инст:sarkison7
0:58
SARKISONCHIK.OFFICIAL
Рет қаралды 5 МЛН