【问题标题】:How to add button to open url with parameter in datatables Laravel 8如何在数据表 Laravel 8 中添加按钮以打开带有参数的 url
【发布时间】:2021-05-15 21:35:12
【问题描述】:

我的数据表视图中显示了一些数据,我想为每个数据添加按钮以打开可以显示更多详细信息的详细信息页面

public function Task(Request $request)
    {    

        if ($request->ajax()) {
            $data = DB::table('posts')
                ->where('jabatan', Auth::user()->jabatan)
                ->select('user_id', 'name', DB::raw('count(user_id) as total'))
                ->selectRaw('SUM(status = "Selesai") as selesai')
                ->selectRaw('count(user_id) - SUM(status = "Selesai") as belum')
                ->groupBy('name')
                ->groupBy('user_id')->get();
            return Datatables::of($data)
                ->addColumn('action', function ($row) {
              
                    $btn = ' <a href="{{route(\'detail.index\',$row->user_id)}}"data-original-title="Detail" class="btn btn-primary mr-1 btn-sm detailProduct"><span class="fas fa-eye"></span></a>';

                    return $btn;
                })
                ->rawColumns(['action'])
                ->addIndexColumn()
                ->make(true);
        }

        return view('task.Task');
    }

该按钮可以出现在我的数据表中,但它会打开 %7B%7Broute('detail.index',$row->user_id)%7D%7D ,

如果在 html 表格中我可以使用&lt;a class="btn btn-info btn-sm" href="{{ route('detail.index',$post-&gt;id) }}"&gt;Show&lt;/a&gt;

如何使按钮在 url 中打开 /detail?提前致谢

【问题讨论】:

    标签: laravel datatable datatables laravel-8


    【解决方案1】:

    因为你已经在 php 中,所以不要使用 {{ }} 刀片语法使用

    $btn = '<a href="'.route("detail.index",['detail'=>$row->user_id]).'"data-original-title="Detail" class="btn btn-primary mr-1 btn-sm detailProduct"><span class="fas fa-eye"></span></a>';
    

    【讨论】:

    • 按钮会重定向到http://127.0.0.1:8000/detail?6如何重定向到http://127.0.0.1:8000/detail/6
    • 添加你的web.php 路线,这样我可以告诉你
    • 我正在使用Route::resource('detail', DetailController::class);
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-04
    • 1970-01-01
    • 2020-12-20
    • 2014-08-20
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多