@[TOC]( laravel-admin V1.7后$from-deleting()不回调解决方法 )
先在对应的TestController 里创建一个form()方
<?php
namespace App\Admin\Controllers;
use App\Models\Test;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;
use Encore\Admin\Form;
use Encore\Admin\Show;
use Illuminate\Support\Facades\Redis;
class TestController extends AdminController
{
/**
* Title for current resource.
*
* @var string
*/
protected $title = '测试';
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new Test());
$grid->column('id', __('Id'));
$grid->column('total', __('次数'));
return $grid;
}
/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
$show = new Show(Test::findOrFail($id));
$show->field('id', __('Id'));
$show->field('total', __('total'));
return $show;
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new Test());
$form->text('total', __('total'));
return $form;
}
}
在对应的model 层创建一个boot()方法
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Test extends Model
{
protected $table = 'test';
protected $guarded = [];
public static function boot()
{
parent::boot();
static::deleting(function ($model)
{
echo json_encode($model);die;
// //这样可以拿到当前操作的行数据
// // 这里处理自己的业务逻辑
// Redis::del("test");
//成功失败的返回结果
if(true){
return true;
}else{
throw new \Exception("无法删除");
}
});
}
}
自己整理的模型删除,都是干货