PHPackages                             pion/laravel-repository-controllers - 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. pion/laravel-repository-controllers

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

pion/laravel-repository-controllers
===================================

v0.9.3(10y ago)033MITPHP

Since Feb 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/pionl/laravel-repository-controllers)[ Packagist](https://packagist.org/packages/pion/laravel-repository-controllers)[ RSS](/packages/pion-laravel-repository-controllers/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

Package in development progress
===============================

[](#package-in-development-progress)

A few lines of code to create a form/create page via the repository way. In default the controller supports all the methods for a CRUD (missing the index/show page, you can implement it on your end). The controller uses the repository class that holds all the standart methods for the model, just create a Repository class for your eloquent model, return the class and thats all.

Changes
=======

[](#changes)

0.9.3
-----

[](#093)

- hotfix for the prepareCreateFormData usage not passing the correct request object
- repository trait support createNavigationForCreateAction and createNavigationForEditAction
- updated RepositoryController to use abstract

0.9.2
-----

[](#092)

- removed crazycodr/standard-exceptions depedency

0.9.1
-----

[](#091)

- the getFormView in both repository controllers has new parameter with current Request
- all the prepareFormData methods has new parameter with current request (last property)
- the ChildRepositoryController trait has request parameter then parent parent object

Requirements
============

[](#requirements)

```
Laravel Framework (5.1, 5.2) - 5.0 not tested

```

Installation
============

[](#installation)

```
composer require pion/laravel-repository-controllers

```

Add the service provider to copy the translations to the app.php config

```
Pion\Repository\RepositoryServiceProvider::class

```

Run the publish command to copy the translations (Laravel 5.2)

```
php artisan publish --provider="Pion\Repository\RepositoryServiceProvider"

```

Run the publish command to copy the translations (Laravel 5.1)

```
php artisan vendor:publish --provider="Pion\Repository\RepositoryServiceProvider"

```

Usage
=====

[](#usage)

- For model (root table/model) without any parent relation use RepositoryControllerTrait
- For model that is owned by different model you can use the ChildRepositoryControllerTrait (you must create the controller for the parent model too)
- You must include the **CrumbsNavigationTrait** (for custom provider use **NavigationTrait** or fork the pion/laravel-support-controllers to implement favorite package ), otherwise the the logic will crash.
- The navigation trait can be added to the base controller.

RepositoryControllerTrait
-------------------------

[](#repositorycontrollertrait)

In construct of the controller use the bootRepository() to prepare the repository data. This will also use translated titles and etc. The best practive is to build your own RepositoryController that uses the trait. Then you can extend the methods fromt trait like a normal class. For default usage you can extend provided `RepositoryController`

```
/**
 * RepositoryController constructor.
 */
public function __construct()
{
    parent::__construct();
    // required!
    $this->bootRepository();
    $this->formView = "admin.season.form"; // the desired form

    // optional
    $this->editTitle = "Editing this entry"; // call after boot!
    $this->formObjectIndex = "season";  // the index of the object in form
    $this->detailModelAction = "edit"; // instead of showing the detail action to show, use the edit page
    $this->setRedirectToEditOnCreate(true);
}

```

or you can use

```
/**
 * RepositoryController constructor.
 */
public function __construct()
{
    parent::__construct();
    $this->bootRepositoryWith("admin.season.form", "Create new!", "Edit this one");
}

```

Implement the createRepository method. You can/need to return the repository

```
/**
 * Creates a AreaRepository repository
 * @return AreaRepository
 */
protected function createRepository()
{
    return new AreaRepository(); // this will use the RepositoryTrait
}

```

You can overide the form data for edit/create and both usages by extending these functions.

```
/**
 * Prepares the form data for all the views
 * @param array $data
 * @param Model|null $object
 * @param Request $request
 */
protected function prepareFormData(array &$data, $object, $request) {}

/**
 * Prepares the data only for the
 * @param array $data
 * @param Model $object
 * @param Request $request
 */
protected function prepareEditFormData(array &$data, $object, $request) {}

/**
 * Prepares the data for create form
 * @param array $data
 * @param Request $request
 */
protected function prepareCreateFormData(array &$data, $request) {}

```

### Customizations for navigation

[](#customizations-for-navigation)

*Supported since 0.9.3 version*

You can customize the own navigation via methods (you can or not call the parent method with the trait subclass):

```
/**
 * Generates the navigation for create action
 * @param Request $request
 */
protected function createNavigationForCreateAction(Request $request)
{
    $this->createNavigation($this->createTitle);
}

/**
 * Generates the navigaiton for edit action
 * @param Request $request
 * @param Model $object
 */
protected function createNavigationForEditAction(Request $request, $object)
{
    $this->createNavigation($this->editTitle, $object);
}

```

ChildRepositoryControllerTrait
------------------------------

[](#childrepositorycontrollertrait)

Very similar boot usage as repository controller with more options:

```
/**
 * Defines the index for the parent object in the form view. Must be in the
 * data of the model (witout the _id)
 * @var string
 */
protected $formParentObjectIndex = "parent";
/**
 * Defines a list of collumns we want to select from the parent. If empty
 * the repository will use the name collumn and the key
 * @var array
 */
protected $parentObjectSelect = [];
/**
 * Defines the collumn for the parent object name
 * @var string
 */
protected $parentObjectNameCollumn = "name";

```

You can overide the form data for edit/create and both usages by extending these functions.

```
/**
 * Prepares the form data for all the views
 * @param array $data
 * @param Model|null $object
 * @param Model $parentObject
 */
protected function prepareFormData(array &$data, $object, $parentObject) {}

/**
 * Prepares the data only for the
 * @param array $data
 * @param Model $object
 * @param Request $request
 * @param Model $parentObject
 */
protected function prepareEditFormData(array &$data, $object, $request, $parentObject) {}

/**
 * Prepares the data for create form
 * @param array $data
 * @param Request $request
 * @param Model $parentObject
 */
protected function prepareCreateFormData(array &$data, $request, $parentObject) {}

```

RepositoryTrait
---------------

[](#repositorytrait)

The repository instance that will handle create/update/destroy and all the form validation needed. You can create own BaseRepository that uses the RepositoryTrait and all the repositories will extend the BaseRepository.

For checkbox validation you can add a list of checkbox indexes that will be validated and will prefill 0 or 1 for the unchecked/checked state. Unchecked the checkboxes will be added to the request with 0 value.

### Must implement

[](#must-implement)

#### getClass

[](#getclass)

You must return the model class

```
/**
 * @return string
 */
protected function getClass()
{
    return Area::class;
}

```

#### getValidationRules($isNew, array $data, $model = null)

[](#getvalidationrulesisnew-array-data-model--null)

A set of validation rules. You can return empty array.

```
protected function getValidationRules($isNew, array $data, $model = null)
{
    return [
        "name" => "required|string|max:255",
        "position" => "required|numeric"
    ];
}

```

Extending the resource methods (or traits) with calling "parent" logic
----------------------------------------------------------------------

[](#extending-the-resource-methods-or-traits-with-calling-parent-logic)

You must use the desired trait and change the traits method you want to extend. Then you can call the method with your own method.

```
use ChildRepositoryControllerTrait {
    store as baseStore;
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request $request
 * @param int $parentId
 * @return \Illuminate\Http\Response
 */
public function store(Request $request, $parentId)
{
    // redirect to new form with old data so we can create same properties easier
    return $this->baseStore($request, $parentId)->withInput($request->except([
        "name", "position", "identifier"
    ]));
}

```

Todo
====

[](#todo)

- update readme
- add example
- separate the navigation usage?

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~46 days

Total

4

Last Release

3661d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ad0f2a11e630f5f386cb8544d42f0c56c2b89258172dae581a33dddcc5de1d83?d=identicon)[pionl](/maintainers/pionl)

### Embed Badge

![Health badge](/badges/pion-laravel-repository-controllers/health.svg)

```
[![Health](https://phpackages.com/badges/pion-laravel-repository-controllers/health.svg)](https://phpackages.com/packages/pion-laravel-repository-controllers)
```

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17818.7k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

591.7k1](/packages/crumbls-layup)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.2k](/packages/tomshaw-electricgrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
