Skip to content

Commit 54ea227

Browse files
author
nejc
committed
docs: improve package description and add repository pattern usage example
1 parent ad1ad5d commit 54ea227

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# Very short description of the package
1+
# LaravelPlus Repository Pattern
2+
3+
A Laravel package that helps you organize all your Eloquent queries for each model in dedicated repository classes, making your codebase more maintainable, testable, and clean. Centralize your data access logic in one spot for each model, following best practices for modern Laravel development.
24

35
[![Latest Version on Packagist](https://img.shields.io/packagist/v/laravelplus/repository-pattern.svg?style=flat-square)](https://packagist.org/packages/laravelplus/repository-pattern)
46
[![Total Downloads](https://img.shields.io/packagist/dt/laravelplus/repository-pattern.svg?style=flat-square)](https://packagist.org/packages/laravelplus/repository-pattern)
@@ -20,6 +22,62 @@ composer require laravelplus/repository-pattern
2022
// Usage description here
2123
```
2224

25+
## Repository Pattern Usage
26+
27+
The repository pattern helps you keep all your Eloquent queries for a model in one place, making your codebase more organized and easier to maintain. With this package, you can create repositories in `app/Repositories` and inject them wherever you need.
28+
29+
### Example: `app/Repositories/UserRepository.php`
30+
31+
```php
32+
namespace App\Repositories;
33+
34+
use App\Models\User;
35+
36+
class UserRepository
37+
{
38+
public function all()
39+
{
40+
return User::all();
41+
}
42+
43+
public function find($id)
44+
{
45+
return User::find($id);
46+
}
47+
48+
public function create(array $data)
49+
{
50+
return User::create($data);
51+
}
52+
53+
// Add more query methods as needed
54+
}
55+
```
56+
57+
### Using the Repository in a Controller
58+
59+
```php
60+
use App\Repositories\UserRepository;
61+
62+
class UserController extends Controller
63+
{
64+
protected $users;
65+
66+
public function __construct(UserRepository $users)
67+
{
68+
$this->users = $users;
69+
}
70+
71+
public function index()
72+
{
73+
$users = $this->users->all();
74+
return view('users.index', compact('users'));
75+
}
76+
}
77+
```
78+
79+
> **Tip:** Place all your model queries in their respective repositories under `app/Repositories` to keep your code clean and maintainable.
80+
2381
### Testing
2482

2583
```bash

0 commit comments

Comments
 (0)