Skip to content

Commit 7e038ac

Browse files
author
Ali Özen
committed
readme update
1 parent f355a5d commit 7e038ac

File tree

1 file changed

+71
-45
lines changed

1 file changed

+71
-45
lines changed

README.md

Lines changed: 71 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,92 @@
1-
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.github.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
1+
# Repository Design Pattern & Laravel Practice
22

3-
<p align="center">
4-
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
5-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
6-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
7-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
8-
</p>
3+
The Repository pattern is a way to organize software code that separates the parts of the code that deal with storing data from the parts of the code that deal with the application's logic.
4+
This separation makes it easier to focus on one part of the code at a time and to change the way data is stored without affecting the rest of the code.
95

10-
## About Laravel
6+
The Repository pattern creates an interface between the application code and the data storage code.
7+
The interface defines a set of standard methods for storing, retrieving, updating, and deleting data.
8+
The Repository class provides an implementation of those methods, using whatever storage technology is appropriate, such as a database or a file system.
119

12-
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
10+
By using the Repository pattern, you can achieve several benefits:
1311

14-
- [Simple, fast routing engine](https://laravel.com/docs/routing).
15-
- [Powerful dependency injection container](https://laravel.com/docs/container).
16-
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
17-
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
18-
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
19-
- [Robust background job processing](https://laravel.com/docs/queues).
20-
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
12+
1. Keep the application logic separate from the data storage logic.
13+
2. Put all the data storage code in one place, making it easier to manage and change.
14+
3. Hide the details of the data storage implementation from the rest of the code.
15+
4. Make it easier to test the application logic by providing a mock implementation of the repository.
2116

22-
Laravel is accessible, powerful, and provides tools required for large, robust applications.
17+
## Implementation
2318

24-
## Learning Laravel
19+
In this project, we use the Repository pattern, which is composed of two parts: an interface and a concrete class that implements it.
20+
The interface defines a set of standard methods that the application code can use to communicate with the data storage code.
21+
On the other hand, the concrete class provides the actual implementation of those methods using the Eloquent ORM.
22+
This allows the application code to interact with the database without having to know the details of the underlying database technology.
2523

26-
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
24+
For example, the `BaseRepositoryInterface` interface defines the methods that can be used to perform CRUD operations on models:
25+
If these lines apply on `CommentRepositoryInterface`, these methods can perform CRUD operations on `Comment` model.
2726

28-
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
27+
```php
28+
interface BaseRepositoryInterface // Or interface CommentRepositoryInterface
29+
{
30+
public function all(): Collection;
2931

30-
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 2000 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
32+
public function find(int|string $id): ?stdClass;
3133

32-
## Laravel Sponsors
34+
public function create(array $data): stdClass;
3335

34-
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell).
36+
public function update(int|string $id, array $data): ?stdClass;
3537

36-
### Premium Partners
38+
public function delete(int|string $id): bool;
39+
}
40+
```
3741

38-
- **[Vehikl](https://vehikl.com/)**
39-
- **[Tighten Co.](https://tighten.co)**
40-
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
41-
- **[64 Robots](https://64robots.com)**
42-
- **[Cubet Techno Labs](https://cubettech.com)**
43-
- **[Cyber-Duck](https://cyber-duck.co.uk)**
44-
- **[Many](https://www.many.co.uk)**
45-
- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)**
46-
- **[DevSquad](https://devsquad.com)**
47-
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
48-
- **[OP.GG](https://op.gg)**
49-
- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)**
50-
- **[Lendio](https://lendio.com)**
42+
The `BaseRepository` class implements `BaseRepositoryInterface` and provides the actual implementation of these methods using the Eloquent ORM:
5143

52-
## Contributing
44+
```php
45+
class BaseRepository implements BaseRepositoryInterface
46+
{
47+
public function __construct(protected Model $model)
48+
{
5349

54-
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
50+
}
5551

56-
## Code of Conduct
52+
public function all(): Collection
53+
{
54+
return $this->model->all();
55+
}
5756

58-
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
57+
public function find(int|string $id): ?stdClass
58+
{
59+
return (object) $this->model->findOrFail($id)->toArray();
60+
}
5961

60-
## Security Vulnerabilities
62+
public function create(array $data): stdClass
63+
{
64+
return $this->model->create([$data])->toArray();
65+
}
6166

62-
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
67+
public function update(string|int $id, array $data): ?stdClass
68+
{
69+
return (object) tap($this->model->findOrFail($id))->update($data)->toArray();
70+
}
6371

64-
## License
72+
public function delete(int|string $id): bool
73+
{
74+
return $this->model->findOrFail($id)->delete();
75+
}
76+
}
77+
```
6578

66-
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
79+
The `CommentRepository` class implements `CommentRepositoryInterface`, extends `BaseRepository` and provides to use override methods|new methods.
80+
For example. If you have to pass specific data when data is not passed, this can be handle in CommentRepository.
81+
82+
## USAGE
83+
84+
The repository pattern is useful in the following scenarios:
85+
86+
1. When you need to switch between different data sources, such as a relational database, a NoSQL database, or a web service.
87+
2. When you need to test the application/business logic in isolation from the data persistence layer.
88+
3. When you need to encapsulate the complexity of the data persistence layer from the application/business logic.
89+
4. When you want to provide a consistent interface for the application/business logic to interact with the data persistence layer.
90+
91+
The Repository pattern can make your code easier to understand and maintain by separating different areas of functionality.
92+
It can also help you make changes to one layer without affecting the other.

0 commit comments

Comments
 (0)