Library created to provide an easy way to develop a Model's CRUD in laravel.

v7.0.1 2020-05-12 14:31 UTC


Software License Total Downloads

This is a library created to provide an easy way to develop a Model's CRUD in laravel.
It provides several traits and classes to allow you to create Controllers that handle automaticaly pagination and create JSON responses in a standard format. Also, it provides a set of traits to implement what we call Model driven Repositories, which allows to have your Models act as data Repositories that can handle filtering, pagination, CRUD operations as well as provide an easy way to create your own custom operations and validations.


This package requires:

  • PHP 7.2+
  • Laravel 6+ or Lumen 5.1+


The compatibility with Laravel is as following


To add dependency to a Laravel 6.x project, run

composer require asp-devteam/laravel-repository "^6.0"


Register Service Provider

Append the following line to the providers key in config/app.php to register the package:


The package supports auto-discovery, so if you use Laravel 5.5 or later you may skip registering the service provider and facades as they will be registered automatically.

Publishing resources

To publish the available translations and config to your application, for customization, just run:

php artisan vendor:publish --tag=repository.translations
php artisan vendor:publish --tag=repository.config


Write a few lines about the usage of this package.

This documentation assumes some knowledge of how Fractal works.

Extending ASP\Repository\Base\Controller

The package has a Controller class, which implements a middleware that handles pagination on index:

use ASP\Repository\Base\Controller;

class YourController extends Controller

Using Model Repository

Option 1: Using the provided Repository

To use the Repository you can use it in your model class:

use ASP\Repository\Traits\Repository;

class YourModel extends Model
    use Repository;

This will make available to you several methods:

  • getAllRecords(Filter $filters = null, array $pagination = null)
  • getRecordById($id)
  • createRecord(Request $request)
  • updateRecordById($id, Request $request)
  • deleteRecordById($id, Request $request)
Option 2: Creating your own Repository

You can also extend the Repository and add your own methods, this also allows you to use Model Validators:

use ASP\Repository\Traits\Repository;
trait YourRepository
    use Repository;

use ASP\Repository\Traits\Repository;

class YourModel extends Model
    use YourRepository, YourModelValidator;

Using Validators

use ASP\Repository\Traits\Validator;

trait YourModelValidator
    use Validator;

     * @return void
    protected static function boot()

                'name' => [
                    'laravel rules here'

     * @return array
    protected static function getCustomRules()
        $rules = self::getBaseRules();

        return array_merge(
              'new rules'

Using Filters

To filter your Model queries you can extend ASP\Repository\Base\Filter:

use ASP\Repository\Base\Filter;

class PetFilters extends Filter
  public function <filterName>(<$parameters>)


Please see CONTRIBUTING for details.


If you discover any security-related issues, please email instead of using the issue tracker.


The MIT License (MIT). Please see License File for more information.

Copyright 2020 Alter Solutions Portugal