laravel package that provides CRUD actions easily.
MIT License
has-crud-action
is a laravel package that provides CRUD actions easily.
You can install the package via composer:
composer require lakasir/has-crud-action
// 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;
}
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,
];
}
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.