lakasir/has-crud-action
Composer 安装命令:
composer require lakasir/has-crud-action
包简介
Has-CRUD-Action is a Laravel package that simplifies adding CRUD (Create, Read, Update, Delete) operations to your models.
README 文档
README
has-crud-action is a laravel package that provides CRUD actions easily.
Features
- CRUD - easily create, read, update, and delete data entities.
- Rules - you can add the rules for your CRUD actions on the fly.
- Magic Parameters - magic parameters that can be used in your actions.
Getting Started
Installation
You can install the package via composer:
composer require lakasir/has-crud-action
Usage
// in your routes file Route::resource('suppliers', SupplierController::class); // in your controller file use Lakasir\HasCrudAction\Abstracts\HasCrudActionAbstract; use App\Models\Supplier; class SupplierController extends HasCrudActionAbstract { public static string $model = Supplier::class; }
Methods
rules the rules method allows you to add your own rules to the action.
public static function rules(): array { return [ 'phone_number' => 'unique:suppliers,phone_number', 'name' => 'required' ]; }
beforeStore the beforeStore method allows you to modify the data before it is stored.
public static function beforeStore($data, $model): Model { $model->name = strtoupper($data['name']); return $model; }
beforeUpdate the beforeUpdate method allows you to modify the data before it is updated.
public static function beforeUpdate($data, $model): Model { $model->name = strtoupper($data['name']); return $model; }
beforeDestroy the beforeDestroy method allows you to modify the data before it is destroyed.
public static function beforeDestroy($model): Model { dd($model); return $model; }
response the response method allows you to modify the response data.
public static function response($record) { return [ 'data' => $record, 'success' => true, ]; }
Magic Parameters
- $id - The ID of the record
- $method - The HTTP method (GET, POST, PUT, PATCH, DELETE)
- $model - The model class name
- $data - The data sent from the request
- $record - The record object associated with the action
- $action - The current method action name
- $route - The current route name
Testing
composer test
Todo
- Pagination support
- Filter support
- ModifyQuery
- Error handler for unsupported magic parameter
- Relation support
- Unit test
- Pipeline
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 email lakasirapp@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.
统计信息
- 总下载量: 3.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-09