Laravel: Repository Pattern in practice

  Рет қаралды 10,717

Przemysław Przyłucki

Przemysław Przyłucki

Күн бұрын

Hi guys!
In this video series, I'll be showcasing a simple way to integrate repository pattern into your Laravel application. We'll start with a super simple example - an app that stores blog posts.
Chapters
00:00 - Introduction & Simple Blog Post
06:12 - Why would you use it
07:24 - Implementation
26:05 - Wrap up
For more content visit saaslaravel.com

Пікірлер: 22
@verard0
@verard0 Жыл бұрын
really nice video! you covered a lot of info! congrats for your work!
@rahmaabdelaziz4095
@rahmaabdelaziz4095 Жыл бұрын
great work
@Muhammed-nani964
@Muhammed-nani964 11 ай бұрын
I think service (action) + DTO is better you may want to create a video on it
@mohammadjavadrajabloo2711
@mohammadjavadrajabloo2711 Ай бұрын
Good Video!
@user-ou5gg7pv4m
@user-ou5gg7pv4m 10 ай бұрын
Hello we made injection on BaseRepository for Model but ı did same things laravel give an error like " Target [Illuminate\Database\Eloquent\Model] is not instantiable while building [App\Http\Controllers\BlogController, App\Repositories\BlogRepository]" when ı make like " $this->app->bind(BlogRepositoryInterface::class,BlogRepository::class);" in AppServiceProvider for solition ı changed this as " $this->app->bind(BlogRepositoryInterface::class,function (){ return new BlogRepository(new Blog()); });" is there any solution ? Thank you for feeds from now ...
@GergelyCsermely
@GergelyCsermely 11 ай бұрын
Hi! I would suggest to use Route::resource
@saaslaravel
@saaslaravel 11 ай бұрын
Never. I hate those! They decrease visibility for me
@parumhr1268
@parumhr1268 9 ай бұрын
what are the advantages to implementing the BlogRepositoryInterface as to just injecting the BlogRepository directly in the constructor??
@saaslaravel
@saaslaravel 9 ай бұрын
You have the freedom to change the implementation of the repository i.e you can change persistence layer or move it to a 3rd party without changing how it interacts with the rest of the application
@user-fx1qh8ml5v
@user-fx1qh8ml5v 5 ай бұрын
Its better to use BlogPost::query()->toBase()->first() instead of BlogPost::first()->toArray(), because in second scenario, laravel convert array from DB to Eloquent, and convert eloquent to array. In first scenario you get raw data without converting
@alexz75515
@alexz75515 Жыл бұрын
Because this line is very long you can tell that this is an enterprise application... 😆
@himasami2200
@himasami2200 Жыл бұрын
can u please give me a source code of this video to study?
@saaslaravel
@saaslaravel Жыл бұрын
I don't have source code for it unfortunately. Will be doing that for any videos going forward 😄
@DailyTechShot
@DailyTechShot 4 ай бұрын
Please people, do not use a repository pattern in Laravel. Laravel has a beautiful active record solution and a repository pattern would only make sense when you would actually want to swap your database implementation, from let's say Mysql to Mongo for example. Do not use 'patterns' for the sake of using them. .
@hydrokat143
@hydrokat143 2 ай бұрын
eloquent can switch over databases with some config changes in the database config and/or eloquent model. question is… is switching from sql to nosql or vv a thing?
@topvova
@topvova Жыл бұрын
Why add an extra layer to Eloquent with interfaces and DTOs? This approach only clutters the code and reduces its maintainability.
@saaslaravel
@saaslaravel Жыл бұрын
I never use it personally but some of the reasons include decoupling the entity model from the database or organisation and reuse of more complex queries
@impulserr
@impulserr 5 ай бұрын
You can mock it easier for tests and it is cleaner imo. I like repositories for readonly eloquent/queries and services on top of that only if I need some more processing/logic + jobs if u need to update/insert/delete. Personally I think it is much better then throwing all to services.
@user-uh6qn1ef1d
@user-uh6qn1ef1d 2 ай бұрын
I personally do controller
@haingocduong5145
@haingocduong5145 4 ай бұрын
Eloquent is a Repository . Don't use Repository Pattern if your Repository get data by Eloquent . it's meaningless
@user-fx1qh8ml5v
@user-fx1qh8ml5v 5 ай бұрын
Its better to use BlogPost::query()->toBase()->first() instead of BlogPost::first()->toArray(), because in second scenario, laravel convert array from DB to Eloquent, and convert eloquent to array. In first scenario you get raw data without converting
Refactoring real-world Laravel app. Who wrote THIS CODE?!
28:02
Przemysław Przyłucki
Рет қаралды 10 М.
Laravel: Simple Strategy Pattern
7:12
Przemysław Przyłucki
Рет қаралды 3 М.
Survival skills: A great idea with duct tape #survival #lifehacks #camping
00:27
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 55 МЛН
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 142 МЛН
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 114 МЛН
Laravel урок №25: [ Что такое Репозиторий? #1 ]
13:12
Refactoring to action pipelines in Laravel
1:25:03
Michael Dyrynda
Рет қаралды 9 М.
Why Don't We Have A Laravel For JavaScript?
12:36
Theo - t3․gg
Рет қаралды 89 М.
Two Things Laravel Services Should NOT Do
8:20
Laravel Daily
Рет қаралды 21 М.
Looking Into a REAL Codebase - Beyond the Basics
10:12
Tech With Tim
Рет қаралды 23 М.
Top 5 Laravel "Bad Practices" (My Opinion)
10:32
Laravel Daily
Рет қаралды 19 М.
🚀 Understanding the repository pattern & why I don't like it 😠
14:39
Laravel: Why Observers and Event Listeners are "Risky"
8:45
Laravel Daily
Рет қаралды 26 М.
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 8 МЛН
Easy Art with AR Drawing App - Step by step for Beginners
0:27
Melli Art School
Рет қаралды 12 МЛН
Красиво, но телефон жаль
0:32
Бесполезные Новости
Рет қаралды 697 М.