laravel-admin 带model数据参数跳转

使用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']));
});
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值