PHPackages                             imdhemy/repovel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. imdhemy/repovel

AbandonedArchivedLibrary

imdhemy/repovel
===============

Implement Repository pattern and add Services layer for Laravel applications

v1.0(6y ago)2992MITPHP

Since Sep 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/imdhemy/repovel)[ Packagist](https://packagist.org/packages/imdhemy/repovel)[ RSS](/packages/imdhemy-repovel/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

repovel
=======

[](#repovel)

Repovel is used to add an extra layer for services and abstract data access using repositories.

**The Service Layer** is a design pattern that will help you to abstract your logic when you need to use different front-end on your application, for your domain logic. Actually, you delegate the application logic to a common service (the service layer) and have only one class to maintain when your application grows or needs an update. This is also a good way to clean up your controllers, and make them more readable. \[[1](https://m.dotdev.co/design-pattern-service-layer-with-laravel-5-740ff0a7b65f)\]

**The Repository Pattern** has gained quite a bit of popularity since it was first introduced as a part of Domain-Driven Design in 2004. Essentially, it provides an abstraction of data, so that your application can work with a simple abstraction that has an interface approximating that of a collection. Meaning, it adds another layer between your application logic and your data source either your database or any external API. \[[2](https://deviq.com/repository-pattern/)\],\[[3](https://www.larashout.com/how-to-use-repository-pattern-in-laravel)\]

Installation
------------

[](#installation)

Run the following command from you terminal:

```
composer require imdhemy/repovel

```

Usage
-----

[](#usage)

**Repovel** extends the awesome artisan commands to add two new commands `make:service` and `make:repository` as follows:

### Services

[](#services)

To create a service class, use the `make:service` Artisan CLI command:

```
php artisan make:service StoreBlogPost

```

If you want to create a Form Request class with the required service, add the option `-r`

```
php artisan make:service StoreBlogPost -r

```

This command creates two classes `App\Http\Services\StoreBlogPost` and `App\Http\Requests\StoreBlogPostRequest`

So how the created services are used? Within your controller method you can instantiate your service and return its `handle()` as a response

- `PostController.php`

```
public function store(StoreBlogPostRequest $request)
{
    return new StoreBlogPost($request);
}
```

Instantiating a service class with a Form request is optional, you can discard the `$request` param:

```
$service = new StoreBlogPost;
```

- `StoreBlogPost.php`Write your service logic inside the `handle()` method:

```
/**
 * Execute service
 *
 * @return mixed
 */
public function handle()
{
    // do some stuff
}
```

You can access the `Illuminate\Foundation\Http\FormRequest` methods inside the service:

```
$name = $this->input('name');
$validated_name = $this->validated('name');
$all_input = $this->all();
```

### Repositories

[](#repositories)

To create a repository class, use the `make:repository` Artisan CLI command:

```
php artisan make:repository PostRepository

```

The created class is found in `app\Http\Repositories`, go and add your required methods to retrieve data.

**N.B.** I found that implementing Repository Criteria or forcing some repository methods like(all, get, find and etc ..) by an interface will limit the usage of the created repositories. It's up to you to use them.

### Full Example

[](#full-example)

```
