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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners