Source: martinjoo.dev

Blog for Laravel Artisans
"The repository pattern abstracts the data store and enables you to replace your database without changing your business code." This is the worst argument in favor of the repository pattern.

Repository is a simple class that contains database queries.

For example: class IssueTrackerRepository { public function createIssue(IssueData $data): Issue { } public function getIssues(string $status): Collection { } public function getCategories(): Collection { } public function getAttributes(): Collection { }}

In a project where I have services and repositories I usually follow these rules: Repository contains database queries.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners