Download the PHP package aldeebhasan/naive-crud without Composer
On this page you can find all versions of the php package aldeebhasan/naive-crud. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aldeebhasan/naive-crud
More information about aldeebhasan/naive-crud
Files in aldeebhasan/naive-crud
Package naive-crud
Short Description A lightweight package to handle the laravel crud operations
License MIT
Informations about the package naive-crud
Laravel Naive Crud
A lightweight package handle laravel api crud operations
Installation
Install using composer:
Optional: After installation run the following code to publish the config:
Basic Usage
This package will help yo to fully customize your crud and have a huge control over each part of your development> No more duplicated code will appear.
Project structure
The best way to understand how the package works is by examples, lets suppose that we want to create a crud for Blogs
Assume that we have a model for blog as App\Models\Blog.php
Controller:
Query handling:
We can control the access to data that need to be returned or exported using a list of re-defined query helpers
Routes:
We have two routes group
-
Resource Routes: will enable the following routs:
- [GET] /resource/search : search for items
- [POST]/resource/import : import items from file import-template based file
- [GET] /resource/import-template: download a template file to use for import
- [GET] /resource/export: export the data
- [POST] /resource/bulk : bulk store
- [PUT] /resource/bulk : bulk update
- [DELETE] /resource/bulk: bulk delete
- [GET] /resource/fields : get the filters and the sort fields
- [PUT] /resource/toggle: toggle columns value
- [GET] /resource : browse the paginated data of the model
- [POST] /resource, : add new item
- [GET] /resource/{id} : get detail of item
- [PUT] resource/{id} : update specific item
- [DELETE] resource/{id} : delete specific item
- File helper Routes: will enable the following routs:
- [POST]/base_path/upload-image : to upload an image
- [POST]/base_path/upload-file : to upload an file
Authorization:
Authorization to access controller resource can be controller using authorize
param, by default it is True
We expect the user has a defined gates of the following form: action_resource,
In our example, if we want the user to have access to the index route, he should have the following ability:
Most of the rules and permissions pacjages define this policies for us based on the user assigned permissions
Resources
By default the package will search for a resource that match the model name.
In our example, the package will look for BlogResource
under namespace App\\Http\\Resources
.
If not found, it will return the $model->toArray()
as response to all the retrieve model routes
Request Forms
By default the package will search for a request form that match the model name.
In our example, the package will look for BlogRequest
under namespace App\\Http\\Requests
.
If not found, it will use a default request class with no rules to control the received data
Filters
We can define a list of filters for each controller to filter the returned data based on some query parameters sent with the api request
When we call the index endpoint .../api/blogs
we can pass the filters as follow
.../api/blogs?filters[search]=title&filters[category_id]=1
and it will filter the results according to them.
You can group the filter fields as you want in any filter class, and you can use any number of filter class as you want
Sorters
Similar to Filters
, we can define some field to order the returned data as we want as follow:
When we call the index endpoint .../api/blogs
we can pass the sorters as follow
.../api/blogs?sorts[id]=desc&filters[tag]=asc
and it will order the results according to the sorters.
You can group the sorter fields as you want in any sorter class, and you can use any number of sorter class as you want
Bulk Operations
In general, the bulk operations use the rules defined for store/update, if you want you can override bulkStoreRules
to add some more rules
Sample request for bulk store:
Export & Import
Simply, you can import the data from an external file.
First you need to download the sample template file useing .../api/blogs/import-template
Then, after you fill some date, you can import it by sending the following request:
NOTE: we expect the file to be uploaded and accessible through the provided file path, Also all the import operation are imported chunk by chunk using the queue
On the other hand, to export any data you can use:
For the case of huge amount of data need to be exported, you can send the export operation to be handled by the queue later.
This operation can be controller by changing $exportAllShouldQueue
in your controller to be `True.
By doing this, a notification will be send to the current user
Important: when you set exportAllShouldQueue=True, you have to define the notification class that will be used to inform the current user
[!IMPORTANT] To enable any model to be imported and exported it should implement the
ExcelUI
InterfaceLicense
Laravel Naive Crud package is licensed under The MIT License (MIT).
Security contact information
To report a security vulnerability, contact directly to the developer contact email Here.