Convenience layer on top of the Laravel framework for developing CRUD applications
carlosafonso/laravel-crud is a Laravel package for convenience layer on top of the laravel framework for developing crud applications.
It currently has 2 GitHub stars and 929 downloads on Packagist (latest version 1.0.0).
Install it with composer require carlosafonso/laravel-crud.
Discover more Laravel packages by carlosafonso
or browse all Laravel packages to compare alternatives.
Last updated
Convenience layer on top of the Laravel framework for developing CRUD applications
This project aims to be a useful layer on top of the excellent Laravel framework to ease up the development of CRUD applications. It avoids developers the repeating tasks of developing CRUD logic and allows them to concentrate on the specifics of their application domains.
Install this package via Composer:
composer require carlosafonso/laravel-crud
Then add Afonso\LvCrud\Providers\LvCrudServiceProvider::class to the list of providers in config/app.php.
Don't forget to publish the configuration file specific to this package:
php artisan vendor:publish --provider="Afonso\LvCrud\Providers\LvCrudServiceProvider"
This will add a new configuration file called crud.php inside your config folder.
Have any of your controllers extend from Afonso\LvCrud\Controllers\CrudController:
use Afonso\LvCrud\Controllers\CrudController;
class FoosController extends CrudController
{
//
}
This will automatically enable the CRUD behavior.
This library assumes that all models are namespaced under App:
App\Controllers\FoosController -> App\Foo
If your code does not follow this convention, the default model namespace can be specified by overriding the getModelNamespace function in your controller.
public function getModelNamespace()
{
return 'My\\Custom\\Namespace';
}
This library expects all related models to implement Afonso\LvCrud\Models\CrudModelInterface. You can either do this for all models or just implement this on a base model class that you will later extend and override if necessary.
By default, CRUD controllers support both JSON and HTML responses. This behavior can be tuned by overriding the following functions:
/*
* In this example we're only supporting JSON responses.
*/
public function supportsJson()
{
return true;
}
public function supportsHtml()
{
return false;
}
Read-only controllers don't allow creating, updating or deleting data.
A controller can be declared as read-only by setting the $readOnly flag to true:
class MyController extends CrudController
{
protected $readOnly = true;
}
Read-only controllers will return with an HTTP status of 405 Method Not Allowed when doing POSTs, PUTs or DELETEs on the resource.
The following attributes can be modified in the configuration file, crud.php:
The default number of entitites per page when the URL param page_size is not specified.