Laravel 6 Advanced - e7 - Repository Pattern

  Рет қаралды 103,753

Coder's Tape

Coder's Tape

Күн бұрын

The Repository Pattern is a common refactor that you may encounter in large Laravel applications. While it is not ideal for small to medium projects, it's a perfect solution for those applications that need an abstraction of the data layer.
For the best experience, follow along in our interactive school at www.coderstape...
DigitalOcean Referral
m.do.co/c/7dce...
Hit us up on Twitter with any questions or comments @codertape ( / coderstape )
About This Course
Ready to level up your Laravel skills? This series is for you, follow along as we uncover the advanced Laravel features that actually make Laravel the most popular php framework. We'll have lot of tips and tricks along the way. Are you ready?

Пікірлер: 224
@morleytechtv7749
@morleytechtv7749 5 жыл бұрын
this is crazy dude. hope you have good health to create more videos. I learn a lot from your videos.
@andynguyen8124
@andynguyen8124 4 жыл бұрын
Dude, that map->format(); is genius, Wow Also I've never know that we can ->diffForHumans() from carbon, thanks so much
@kasmanialisaad
@kasmanialisaad 5 жыл бұрын
These advanced series are very helpful. Thanks!
@CodersTape
@CodersTape 5 жыл бұрын
Happy to hear that. More advanced topics are much more time consuming in preparation leading up to recording the lesson.
@julienSibille
@julienSibille 5 жыл бұрын
@@CodersTape Thanks for your work Victor, what about another Udemy course applying those advanced concept ?
@priteshshinde6779
@priteshshinde6779 4 жыл бұрын
We understand that it is more time consuming, but you know you've got 1 more subscriber just now (me). I'm sure you'll get alot more subscribers until this series end, but please make more videos.
@abunooh9005
@abunooh9005 5 жыл бұрын
I never comment on anything, but this series is just too helpful. You are my new Laravel teacher. Keep it up and thank you very much. You are awesome!
@victorwillhuber
@victorwillhuber 2 жыл бұрын
Man, I watch A LOT of educational videos on coding (php, js, laravel, vue) and you are the best.
@agent_mo
@agent_mo 3 жыл бұрын
your practical explanation is phenomenal. Keep up the good work please, people like us depend on you.
@phentube2345
@phentube2345 4 жыл бұрын
where were you, finally I found someone that knows pure implementation and architecture.
@ahmadmayahi
@ahmadmayahi 4 жыл бұрын
The repository should only be used to reterive the data. It's a common mistake that some developers use repositories for storing/updating/deleting, but it’s not meant to be like that. If you need to store/update/delete then you have to have a persistent layer. I think Doctrine did the best implementaion of repositories.
@dr.adam.nielsen
@dr.adam.nielsen 3 жыл бұрын
In literature you find that the main purpose of repositories is to be a layer between your data mapping and the business logic. Its totally fine to store/update/delete date there. See stackoverflow.com/questions/57340681/should-we-save-update-models-in-repository-pattern
@Wane-maxx
@Wane-maxx 8 ай бұрын
So what are we supposed to use instead of repos?
@ProgrammingwithPeter
@ProgrammingwithPeter 5 жыл бұрын
Cool, unfortunately beginners take Repository as granted, glad that you pointed out that it is meant for larger apps!
@AirMalta89
@AirMalta89 5 жыл бұрын
This course is amazing. Not the usual blah-blah most good laravel devs already know. But really insightful, solving real-life problems where you were thinking as a dev, there should be a nicer solution for this!
@mohammedmahmoud1182
@mohammedmahmoud1182 3 жыл бұрын
The best coding channel out there. I hope you post more videos as you used to.
@wanamra899
@wanamra899 2 жыл бұрын
I never not like every single video i watched from this dude. Thanks a lot bro.
@Yuri-sf5mx
@Yuri-sf5mx 5 жыл бұрын
Watched this video to fresh up my memory on repositories and honestly you make great videos and your explanation is to the point. Love your style. On the subject though i do find that the only reason you should use repositories is when you expect to swap out your database for something else. Other than that i stick with model query scopes for the repetitive query's (powerfull for their chainability) and use resources to format them. Even on very large projects. You could still use repositories in combination with these, but as said, the only added value is data driver independency. *Edit* Looks like this has been said a few times. Either way, it boils down to project requirements and personal favor. There is no "right" way.
@CodersTape
@CodersTape 5 жыл бұрын
Absolutely.
@utshabroy
@utshabroy 5 жыл бұрын
Thanks you for this video. I learned a lot. However, I read some blog where the Repository is connected with the ServiceLayer. If I'm right then can you please make a video on how Repository and ServiceLayer works together on big projects. Thank you again 😊 you are the best Laravel tutor.
@Stoney_Eagle
@Stoney_Eagle 5 жыл бұрын
I will definitely implement the format function, I feel like I've been repeating myself a lot on database queries. Thanks!
@brunofunnie
@brunofunnie 3 жыл бұрын
Experiment Fractal
@josebriceno7578
@josebriceno7578 2 жыл бұрын
Crazy good content, thanks a lot for posting this. The quality of this video is unreal. God bless you man!!
@ammaralhomyqani9079
@ammaralhomyqani9079 3 жыл бұрын
Thank u so much, we need people like you in this world
@MarcoAZeballosS
@MarcoAZeballosS 5 жыл бұрын
It's the first time I get to clearly understand Repositories. I cannot pass to the next video without congratulating you and thanking you for such amazing video/explanation. 👏🏼👏🏼👏🏼
@CodersTape
@CodersTape 5 жыл бұрын
Thanks
@Wane-maxx
@Wane-maxx 9 ай бұрын
well, you are still not, because repo pattern is not needed when using laravel
@MustafaBirsoz
@MustafaBirsoz 3 жыл бұрын
I love your tone and the content here
@yuchenglong672
@yuchenglong672 4 жыл бұрын
I think for those who don't potentially change their projects databases, a cleaner way is to implement a eloquent based repository design pattern, that works specifically with laravel eloquent, and just so much cleaner and readable. For a large projects which may be deployed with different types of dbs, a middle layer like the repository interface design pattern is almost like a must go-to idea.
@aristideherve5748
@aristideherve5748 5 жыл бұрын
You are incredible ! I asked for a video on it in your last video and you did it. Everything is clear ans precise. God bless you!
@ahmadmayahi
@ahmadmayahi 4 жыл бұрын
12:19 You can avoid mixing transformers into repositories by using an external transformer. In this case, the fractal package would be amazing to use.
@KuroUsagi1010
@KuroUsagi1010 2 жыл бұрын
May I ask where they are going to be called when formatting? should it be on the controller? or on the repository?
@yurabobrov6717
@yurabobrov6717 5 жыл бұрын
If I could to press "Like" twice, I would do it! Awesome tutorial as always.
@milantarami
@milantarami 5 жыл бұрын
Learning more advanced things in this advanced laravel series, out of the box :) .... Need a tutorial on Service Pattern implementation
@shaheerarain50
@shaheerarain50 4 жыл бұрын
I was smiling while watching your video and thinks how a person could be so good at ♥️ Thank you
@paolopalubs64
@paolopalubs64 5 жыл бұрын
Very informative! I've been using using model repositories for a long time now, and this is a good tutorial for those who haven't tried it yet. This is useful specially when doing reports.
@oghenerukevwekofi7976
@oghenerukevwekofi7976 4 жыл бұрын
I think repositories are also beneficial for testing. When you have the data layer coded against an interface like this, it becomes easier to mock it while testing. Depending on your needs, I think you might want to be able to separate tests that will reach the database from tests that just see if your basic functionality is working or not.
@nullpadshot
@nullpadshot 5 жыл бұрын
Collection()->map->formatCallback()? and you dont kidding? Freakin awesome! That save me at least 1000 rows of code! Awesome! Thank you so much!
@MrAlaa3344
@MrAlaa3344 4 жыл бұрын
you're the best ever in explaining leravel
@fabianleon1744
@fabianleon1744 5 жыл бұрын
Thank you very much for these videos 🙌. I have read many times about the repository pattern, but this is by far the best explanation I have found.
@ssjuma
@ssjuma 4 жыл бұрын
Interface implementation was my best part, loved it!
@peymanGhaderkurehpaz
@peymanGhaderkurehpaz 4 жыл бұрын
awesome , can you make more videos like this ? implementing design patterns and advanced php and laravel technics are awesome . Thanks again
@rahulshimpi8914
@rahulshimpi8914 5 жыл бұрын
Great great video please make more advance video. You are really professional programmer.
@TUTORIALSUZ
@TUTORIALSUZ 4 жыл бұрын
Thank you, bro!!! You are awesome! I learnt everything I'm confused. Thank you for your lessons. Sincerely, Sanjarbek from Uzbekistan.
@serhiicho
@serhiicho Жыл бұрын
Quick note. You bind interfaces in register() method of the service provider
@tonviet712
@tonviet712 5 жыл бұрын
This map->format() blow my mind. That’s incredible video. But I still have some confusions: I knew about this pattern, but still don’t understand why this is necessary. Does it put all of logic to get data from Model to Repository? What pros and cons when put all logic in Model instead of Repository? Thank in advance
@CodersTape
@CodersTape 5 жыл бұрын
truthfully, I think it's a design decision more than anything. I particularly like heavy models and don't use repository patterns. One use case I can understand is when you are managing several different data sources and need to access them equally. Example might be news, let's pretend you are receiving news feeds, one is coming as an RSS feed, another is content written in-house and maybe 3-4 different sources. Repository will make the consolidation easier because they can be treated differently but accessed with the same API.
@tonviet712
@tonviet712 5 жыл бұрын
Coder's Tape You are my new fav teacher. Great explanation !!! Thanksssss
@CodersTape
@CodersTape 5 жыл бұрын
@@tonviet712 Thanks!
@adaamgbede283
@adaamgbede283 4 жыл бұрын
Nice video. I really learn a lot. I wonder why people gave this a thumb down
@hassanalthaf8561
@hassanalthaf8561 4 жыл бұрын
I would honestly keep that format method within the Repository, as when you're writing a new concrete implementation of the repository, you might miss out on that specific business rule.
@Brianle180
@Brianle180 5 жыл бұрын
Just totally love all your tutorials. Keep it up.
@dilipdev8699
@dilipdev8699 2 жыл бұрын
Really amazing!. What about next point after implementation the interface?. Even without the interface we can do the same things. Then what's the purpose of the interface here?.
@Darren502
@Darren502 5 жыл бұрын
This is a great ep. Thx for showing us this. Would you make a video on caching?
@personal1872
@personal1872 Жыл бұрын
hi there, it's been long that you haven't published a video, I love your content, please start making videos again :)
@sardinas3675
@sardinas3675 5 жыл бұрын
This is fr**king awesome my friend! I hope that someday or in the future that you will create a video on SOLID pattern in laravel. Btw You are the best
@CodersTape
@CodersTape 5 жыл бұрын
Thanks
@codewithtee
@codewithtee 3 жыл бұрын
@@CodersTape have you big man?
@SunilparajuliKenshin
@SunilparajuliKenshin 4 жыл бұрын
This is the best quality content coding pattern
@loremipsum574
@loremipsum574 5 жыл бұрын
Please create a SOLID pattern tutorial. It would help a lot of beginners like me.
@tarikhagustia939
@tarikhagustia939 5 жыл бұрын
up
@CodersTape
@CodersTape 5 жыл бұрын
Would you say it would be better to exclude Laravel from it and keep it simple with plan PHP?
@loremipsum574
@loremipsum574 5 жыл бұрын
@@CodersTape I mean SOLID pattern in laravel. If you search on the web there's no such thing as SOLID pattern tutorial it would be you the first one will do it. There's a solid pattern tutorial but not complete.
@Eugene.g
@Eugene.g 5 жыл бұрын
@@CodersTape SOLID principles and design patterns are pretty abstract, so real life examples with refactoring in Laravel would be awsome to see. I think youtube lacks this type of advanced content on how to structure a Laravel app and how to use patterns
@Yuri-sf5mx
@Yuri-sf5mx 5 жыл бұрын
This is something i hear a lot from beginners and had issues with myself when i started using Laravel. Laravel is great because it's all very "loosely", but as a beginner you have no clue how to organize files/namespaces, how to name classes, how to write functions, how to separate things, ... But i don't think a solid "all use case" pattern is possible because not all project will fit this pattern. A pattern is required, but should be on project level and defined in the abstract layout of your project. Before the first line of code is written the pattern should be established.
@xdEdgarBest
@xdEdgarBest 5 жыл бұрын
Your videos are simply the best, thank you
@Moonlit_Loops88
@Moonlit_Loops88 2 жыл бұрын
thanks for creating such amazing video , i really love the way u clear concept in depth .
@vrabecm
@vrabecm 5 жыл бұрын
Dude, nice tutorials. Only 1 cent from me: I think repositories should be used entirely for one purpose - retrieving data. Update, store and delete functions should be found in the model or a Service.
@CodersTape
@CodersTape 5 жыл бұрын
I’ve seen it both ways in the wild. And I see both points of views.
@vrabecm
@vrabecm 5 жыл бұрын
@@CodersTape Yeah, I agree, it's a personal opinion. Anyway, keep up with the videos, they are absolutely amazing.
@ahmedhamza9277
@ahmedhamza9277 Жыл бұрын
that's greate, greate series, greate demonstrations and easy to understand, thanks man :))))
@colonelvector
@colonelvector 4 жыл бұрын
Excellent explanation, grasped it immediately.
@mori181186
@mori181186 5 жыл бұрын
This is why i love Laravel. Thanks for your good videos :)
@Laflamablanca969
@Laflamablanca969 4 жыл бұрын
I find formatting with Resources is much more flexible
@peymanGhaderkurehpaz
@peymanGhaderkurehpaz 5 жыл бұрын
That was awesome , thanks , these Advanced video series are awesome .
@ayazahamed8254
@ayazahamed8254 2 жыл бұрын
Very well explained. Useful content.
@anoopsankar7726
@anoopsankar7726 3 жыл бұрын
This is very useful. I learnt a lot. Thanks for the video.
@phoe7ix
@phoe7ix 4 жыл бұрын
An extremely useful lesson, thank you, Victor!
@2012potter
@2012potter 4 жыл бұрын
Awesome. You could've used Eloquent resources instead of format() right?
@KistlakRajapakshaSevenNet
@KistlakRajapakshaSevenNet 5 жыл бұрын
100% Perfect !! Thank You very Much Bro !! :D
@KoganeNoYubi
@KoganeNoYubi 4 жыл бұрын
great stuff, but how would you combine repositories with API resources?
@melomancheto2761
@melomancheto2761 4 жыл бұрын
I do not agree on the part of format and transform. You can't choose format, formating is for dates for examples. What we are doing with this data is transforming it . But the tutorial and not only this one, all of them are awesome!! Keep up the great content. Something else is that the request has nothing to do with the Repository. The repo is just a middle layer between the database and the Controller (I use this example to be more close to Laravel). We need to pass all the data we need as params and never pass the Request outside of the Controller.
@limuelmendoza5356
@limuelmendoza5356 3 жыл бұрын
i hope i've seen your channel before my project... life shouldve been way easier
@carlosmillanmazzucco1766
@carlosmillanmazzucco1766 3 жыл бұрын
My god dude! thanks so much!! this video clarified me a lot of things. Love ur channel and content! cheers
@maharagab5107
@maharagab5107 5 жыл бұрын
Very helpful , I was waiting for it thank you so much, really appreciate all the valuable content you provided thanks again!
@RichardOpokuEngineer
@RichardOpokuEngineer 5 жыл бұрын
I have implemented the repository pattern before and this has been really helpful to add to my understanding. However, some folks somewhere on the internet claim that it should rather be a service layer and not repositories. I recently had to refactor one source code to reflect *services* instead of the *repositories* I had already implemented. I need help understanding these further.
@CodersTape
@CodersTape 5 жыл бұрын
The service layer is the abstraction of the controller where the repository is the abstraction of the model. Typically you inject a repository into the service layer so you would still need both and it's just yet another abstraction layer between the view and the controller. So the order would be Controller > Service > Repository > Model is it better? I can't agree that it is in most cases. I think it's just hiding away bad code design but I am open to seeing some code samples. :)
@truthseeker2171
@truthseeker2171 5 жыл бұрын
@@CodersTape Wow, that's quite interesting. I am implementing a payment gateway (API) with an ecommerce app where I would like to have a lot of the business logic in the services and then manipulate the data using Repositories. But while following the above structure, *Controller > Service > Repository > Model* where will FormRequests come in for validation?
@TolvirRam
@TolvirRam 3 жыл бұрын
Thanks a lot. Finally I understand repositories :))
@THEShAdOwHFV
@THEShAdOwHFV 7 ай бұрын
Min 21:00 For those that can't load the provider when registering it in app.php file (test the provider with dd("plainText")) You can do: php artisan config:clear php artisan clear-compiled composer dump-autoload If composer is failing, just delete the "dd("test")" in your provider
@mubashirali5687
@mubashirali5687 2 жыл бұрын
Great explanation about repository pattern :-)
@amirkaftari5188
@amirkaftari5188 3 жыл бұрын
dude come back and create amazing tutorials for us.
@kevteg7305
@kevteg7305 5 жыл бұрын
I think it better to use Scope Modele to manage that in pure laravel way.
@CodersTape
@CodersTape 5 жыл бұрын
Both techniques have a time and place. It’s good to know both.
@rolanddecasa4438
@rolanddecasa4438 3 жыл бұрын
Another good one! Keep it up bro! God bless you
@mohd.aadilads3889
@mohd.aadilads3889 Жыл бұрын
Very good explanation 🎉🎉
@shirjeelkhan
@shirjeelkhan 5 жыл бұрын
Great work...please go ahead. When is the next one e8 ?
@joshbarros1995
@joshbarros1995 3 жыл бұрын
Nice video! Do you intend to teach how to apply Services, TDD and Domain Driven Design on Laravel 8?
@djanthony6662
@djanthony6662 4 жыл бұрын
I think some of these concepts could be done by using Query Scope for readability if you are using Eloquent: $customers = Customer::isActive()->orderBy('name', 'asc')->withUser()->get(); then pass that to API resource class for formatting: use App\Http\Resources\CustomerResource; return new CustomerResource::collection($customers);
@SamehNabilAhmed
@SamehNabilAhmed 5 жыл бұрын
you are awesome dude
@CodersTape
@CodersTape 5 жыл бұрын
Thanks! Happy to help
@vimkndll4171
@vimkndll4171 4 жыл бұрын
mind blowing video I have ever seen in the youtube
@asdf7972
@asdf7972 5 жыл бұрын
Mannn i really love this course!!!
@JordiViure
@JordiViure 5 жыл бұрын
Great! But.. this actions implemented in the repository can not be implemented inside the model? What s the difference? Thanks!!
@CodersTape
@CodersTape 5 жыл бұрын
The difference is that if you don’t want to use a database or Eloquent, you can’t use the model. You can write a flat file implementation for example or use Redis or anything else you can think of to provide the data, not just a traditional database. It can even be provided by an API.
@golubevblog2279
@golubevblog2279 5 жыл бұрын
WONDERFUL DUDE! KEEP GOING! U'RE A MAN!
@haki3018
@haki3018 4 жыл бұрын
using request() in repository very nice
@mohamedtalaat8945
@mohamedtalaat8945 4 жыл бұрын
Thanks for this great episode!
@MrNescafe87
@MrNescafe87 3 жыл бұрын
thanks for your explaination for this pattern and it helps so much but i actually have some questions. i know the reason for using the repository pattern but isn't this is why we use services classes ? For example " Making a UserService Class and inject it in controller and retrieve the users like : $this->userService->getAll() ? And why using the map method to format the response and not use the resources ?
@tsalVlog
@tsalVlog 4 жыл бұрын
I had no idea PHP had real interfaces now. It's been a while...
@juanmanuelmazariegos4598
@juanmanuelmazariegos4598 3 жыл бұрын
Hello, amazing video, sorry, where going the logic?
@robert5488
@robert5488 5 жыл бұрын
Thanks very much for these videos! They are brilliant, concise and very clear. Better than Laracasts. Would love to see more videos on design patterns and clean code fundamentals.
@ristekostadinov2820
@ristekostadinov2820 5 жыл бұрын
If more than one class implements the CustomerRepository then in boot method of the provider we should register both of them (the interface with the first class and the interface with the second class) ? For example you can implement the interface with 2 classes one with pure eloquent ORM and second class with query builder
@Kortess
@Kortess 5 жыл бұрын
Hi, are there any plans for Docker lessons?
@Brianle180
@Brianle180 5 жыл бұрын
I am wondering that in this case, what is correct when we put the interface’s binding in ‘boot’ or ‘register’ function?
@mohaimenkhalid3844
@mohaimenkhalid3844 3 жыл бұрын
just a awesome video bro!! thanks a lot bro
@SimpleLangSolution
@SimpleLangSolution 2 жыл бұрын
Wow! This is amazing! You are a god!
@NathanBudd
@NathanBudd 5 жыл бұрын
Would love a video on Lazy Collections 👍
@CodersTape
@CodersTape 5 жыл бұрын
That’s next!
@zohaibtariq-software-engineer
@zohaibtariq-software-engineer 3 жыл бұрын
after adding RepositoriesServiceProvider to config\app you must need to run php artisan config:cache after this it will work.
@manzadey
@manzadey 4 жыл бұрын
Eloquent is already a repository isn't it? Does it make sense to create another repository above the repository?
@carlosolivas2878
@carlosolivas2878 5 жыл бұрын
it is a very nice course, thanks!
@Paltibenlaish
@Paltibenlaish 4 жыл бұрын
question> why dont use the model to write directly the methods there??? why extra layer of abstraction?
@adrianhojny2920
@adrianhojny2920 4 жыл бұрын
Show it to guys from India, who take all logic to controllers :')
@jeck0898
@jeck0898 4 жыл бұрын
Thanks so much for this tutorial
@dgloria
@dgloria 4 жыл бұрын
What's the difference between this and the resources? And how to handle more than one table?
@AlexandrStiopkin
@AlexandrStiopkin 5 жыл бұрын
Nice video but it is a bad idea to use request inside of a repository because repository it is a part of a domain layout.
@thekiharani
@thekiharani 5 жыл бұрын
Cool stuff, but I got a query: I there a way you can paginate the records either before or after you transform?
Laravel 6 Advanced - e8 - Lazy Collections & PHP Generator
20:28
Coder's Tape
Рет қаралды 35 М.
Laravel 6 Advanced - e2 - View Composers
22:12
Coder's Tape
Рет қаралды 69 М.
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,5 МЛН
iPhone or Chocolate??
00:16
Hungry FAM
Рет қаралды 51 МЛН
Laravel. Сервисы, контракты и внедрение зависимостей
29:18
Lectoria. Обучение веб-разработке.
Рет қаралды 22 М.
Repository Pattern
11:08
Coding Concepts
Рет қаралды 68 М.
Laravel урок №25: [ Что такое Репозиторий? #1 ]
13:12
Laravel 6 Advanced - e1 - Service Container
23:27
Coder's Tape
Рет қаралды 274 М.
Deep Dive Into the Repository Design Pattern in Python
11:56
ArjanCodes
Рет қаралды 77 М.
Laravel.su #18: Плюсы и минусы паттерна "Repository".
23:12
Кирилл Несмеянов
Рет қаралды 10 М.
LARAVEL + Clean Architecture // Роман Постников
24:03
Студия Флаг
Рет қаралды 10 М.
Laravel + Service Pattern + DTOs = ❤️❤️❤️
17:52
Przemysław Przyłucki
Рет қаралды 50 М.
Laravel Code Review: Why NOT Use Repository Pattern?
14:21
Laravel Daily
Рет қаралды 78 М.
Laravel 6 Advanced - e6 - Pipelines
28:53
Coder's Tape
Рет қаралды 52 М.