php - Not found page when clicked detail to get data based on id

Solution:

I will try to fix what i think it's wrong in your code.
First you should give the $data to your blade file

Controller method

 public function detail($id)
        {
          $data = DB::table('lirik_lagu')->where('id', $id)->first();
    
          return view ('admin.detail-lirik',['data'=>$data]);
        }

Second, your should omit the $ in your Route id parameters
Route

Route::get('lirik-lagu/detail/{id}', [LirikLaguController::class, 'detail']);

Third, when you generate the url url(...) it seems to have an admin prefix but not your route declaration.
Blade

  <a class="btn btn-success btn-sm" href="{{ url('lirik-lagu/detail', $data->id) }}">Detail</a>

Answer

Solution:

You are not passing the variable to the view. This is how you do it:

return view('admin.detail-lirik', $data);

If you need to pass multiple variables you can pass an array in the second paramter like this:

return view('admin.detail-lirik, ["varname" => $var]);

Answer

Solution:

I see several problems here, so I'm going to point them out. First one, you never returned the data to your view:

return view ('admin.detail-lirik', $data);

The other is the URL in your blade file. You called admin/lirik-lagu/detail but you defined route without admin in your web.php file. You can remove the admin from your url, or create a name for your route and call it that way:

Route::get('lirik-lagu/detail/{$id}', [LirikLaguController::class, 'detail'])->name('lirik-langu');

And then use it like this

<a class="btn btn-success btn-sm" href="{{ route('lirik-langu', $data->id) }}">Detail</a>

Source