0

I have some data shown in my datatable view, I want to add button to each data to open detail page which can show more detail information

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');
    }

the button can appear in my datatable, but it will open %7B%7Broute('detail.index',$row->user_id)%7D%7D ,

If in a html table I can use <a class="btn btn-info btn-sm" href="{{ route('detail.index',$post->id) }}">Show</a>

how to make the button to open /detail in url? thanks in advance

1 Answer 1

1

as your in already in php so don't use {{ }} blade syntax use

$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>';
Sign up to request clarification or add additional context in comments.

3 Comments

The button will redirect to http://127.0.0.1:8000/detail?6 how to redirect to http://127.0.0.1:8000/detail/6
add your web.php route so i can tell u
Im using Route::resource('detail', DetailController::class);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.