Download the PHP package ebalo/easycrud without Composer
On this page you can find all versions of the php package ebalo/easycrud. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package easycrud
Laravel easy-crud
This package was created to avoid the repetitive task of creating standard crud endpoints in Laravel applications, the ultimate goal is to let you create your standard crud endpoint in less than a minute without having to worry about all the repeating tasks.
Installation
You can install the package via composer:
Then proceed with the package initialization with:
In case you want to manually install the trait for all your controller or only install it for some of them you should:
- Incude
use Ebalo\EasyCRUD\EasyCRUD;
in the controller that needs the trait - Include
use EasyCRUD;
inside the controller body
Usage
The package provide two method to access all the function:
- The preferred one is through the usage of the EasyCRUD trait, inserted automatically on your main controller when completing installation
- The second method is through the usage of the helper functions
Usage through trait
The trait exposes four main functions, these are:
easyCrud
It performs the basic crud operation, it is the most flexible method and is the base for all the other methods.easyStore
It is specifically designed to store a new model instance.easyUpdate
It is specifically designed to update an existing model instance.easyDelete
It is specifically designed to delete an existing model instance.
The store and update procedure relay on the rules
array to retrieve the parameter from the request.
The rules
array is a standard laravel validation array as the ones used in the Validator::create
method or in the
standard validate
method of the controller class.
Example usage
You may have noted that the rules has a unique check on the name
parameter, this check is automatically dropped in the
update phase in order to let you easily update the model without any warning.
All the previous methods can also be written with the usage of the standard and more flexible easyCrud
function,
see the following example.
You see that the easyCrud
is not that different from the previous examples.
Usage through helpers
There are four helper functions, these are:
easyCrud
It performs the basic crud operation, it is the most flexible method and is the base for all the other methods.easyStore
It is specifically designed to store a new model instance.easyUpdate
It is specifically designed to update an existing model instance.easyDelete
It is specifically designed to delete an existing model instance.
The store and update procedure relay on the rules
array to retrieve the parameter from the request.
The rules
array is a standard laravel validation array as the ones used in the Validator::create
method or in the
standard validate
method of the controller class.
As you can see the name are exactly the name of the functions available with the trait, this is done in order to let you
remember only one function name.
Example usage
The example usage is a bit more difficult and tedious than the previous one, check the following examples of the same methods implemented previously.
All the previous methods can also be written with the usage of the standard and more flexible easyCrud
function,
see the following example.
Additional functionality
As creating CRUD routes is almost always a copy-paste of previously created code, the package is shipped with a
CRUD
helper that can be easily called from inside your routes.
See the following examples.
The above code works exactly like the following one.
If you don't want to generate all the predefined crud routes you can pass also an additional associative array like the following example.
The above code is the same as the following.
There is also a last additional way to call the CRUD
function, it gives you the possibility to change the function to
call once the route is executed, see this last example.
The above code is the same as the following.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please use the issue tracker.
Credits
- ebalo
- All Contributors
License
The MIT License (MIT). Please see License File for more information.