PHPackages                             arungpisyadi/laravel-repository-and-service-pattern-pack - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. arungpisyadi/laravel-repository-and-service-pattern-pack

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arungpisyadi/laravel-repository-and-service-pattern-pack
========================================================

Simple repository, service pattern for laravel that works!

v0.0.3(3y ago)0230MITPHPPHP ^8.0|^9.0

Since Aug 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/arungpisyadi/laravel-repository-and-service-pattern-pack)[ Packagist](https://packagist.org/packages/arungpisyadi/laravel-repository-and-service-pattern-pack)[ Docs](https://github.com/arungpisyadi/laravel-repository-and-service-pattern-pack.git)[ RSS](/packages/arungpisyadi-laravel-repository-and-service-pattern-pack/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (3)Dependencies (8)Versions (4)Used By (0)

Simple repository pattern for laravel, with services!
=====================================================

[](#simple-repository-pattern-for-laravel-with-services)

With easy repository, you can have the power of the repository pattern, without having to write too much code altogether. The package automatically binds the interfaces to the implementations, all you have to do is change in the configuration which implementation is being used at the moment!

Requirement
-----------

[](#requirement)

- Laravel 8
- PHP 7.4||8.\*

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

[](#installation)

You can install the package via composer:

```
$ composer require yaza/laravel-repository-service
```

Publish the config file with (Important):

```
php artisan vendor:publish --provider="LaravelEasyRepository\LaravelEasyRepositoryServiceProvider" --tag="easy-repository-config"
```

The configurations in the config file are standard, and can be extended with/depending on further requirements. No need to change any of the contents, unless you are very aware of what you are doing :) This is the contents of the published config file:

```
return [
    /**
     * The directory for all the repositories
     */
    "repository_directory" => "app/Repositories",

    /**
     * Default repository namespace
     */
    "repository_namespace" => "App\Repositories",

    /**
     * The directory for all the services
     */
    "service_directory" => "app/Services",

    /**
     * Default service namespace
     */
    "service_namespace" => "App\Services",

    /**
     * Default repository implementation
     */
    "default_repository_implementation" => "Eloquent",

    /**
     * Current repository implementation
     */
    "current_repository_implementation" => "Eloquent",
];
```

Quick usage
-----------

[](#quick-usage)

This package overrides the default laravel `php artisan make:model User` command, and adds a few flags that can help you set up repository and service quickly.

```
// will genearate controller, factory, service, seeder, repository, resource and migration
php artisan make:model User --all

// use the service and repository flag to generate the class
php artisan make:model User --service --repository

// use the short form to generate model with service and repository
php artisan make:model User -sr -rt
```

You can also create only the repository, or service, or both:

```
php artisan make:repository User
// or
php artisan make:repository UserRepository

// or create together with a service
php artisan make:repository User --service
// or
php artisan make:repository UserRepository --service

// or create a service separately
php artisan make:service User
// or
php artisan make:service UserService
```

The `php artisan make:repository User` will generate two files. One for the interface, and one for the repository class. The interface is bound to it's counter part class automatically depending on the current implementation being used. If the implementation for an interface is not provided, you can provide one manually or otherwise, attempting to use the service will bring up an error.

Eloquent is the default implementation. Other implementations will be added in the future. This is because the package was mainly to simplify usage of the repository pattern in laravel. The classes created are:

```
// app/Repositories/Interfaces/UserRepository.php
