使用laravel-admin的时候不知道如何在添加的跳转按钮上增加传递参数。
创建 php artisan admin:action Post\Comments --grid-row --name=“跳转”
namespace App\Admin\Actions\Post;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
class Comments extends RowAction
{
public $id;
public function __construct($id){
$this->id=$id;
}
public $name = '跳转';
public function handle(Model $model)
{
// $model ...
return $this->response()->success('Success message.')->refresh();
}
public function href(){
return "users/".$this->id."/edit";
}
}
创建一个构造函数传入需要传参的id值并赋值,然后在href()方法中直接调用。
在Controller中添加这个跳转时传入id数据即可
$grid->actions(function ($actions) {
$actions->add(new Comments($actions->row['id']));
});