phphtmlcsslaravelxampp

so I am trying to route gayahidup.blade.php to berpakaian.blade.php but it gives me an error "Undefined variable $berpakaian"


it gives me an error like this

and then if you take a look at my code in controller and web.php

Route::get('/gayahidup/{id}',[GayaHidupController::class,'showGayaHidup'])->name('gayahidup.show');
Route::get('gayahidup', [GayaHidupController::class, 'index'])->name('gayahidup.index');
Route::get('gayahidup/create', [GayaHidupController::class, 'create'])->name('gayahidup.create');
Route::post('gayahidup/store', [GayaHidupController::class, 'store'])->name('gayahidup.store');
Route::delete('gayahidup/{id}', [GayaHidupController::class, 'destroy'])->name('gayahidup.destroy');
Route::get('/gayahidup/berpakaian/{id}', [GayaHidupController::class, 'showBerpakaian'])->name('gayahidup.berpakaian.detail');
Route::get('/gayahidup/kecantikan/{id}', [GayaHidupController::class, 'showKecantikan'])->name('gayahidup.kecantikan.detail');
Route::get('/gayahidup/traveling/{id}', [GayaHidupController::class, 'showTraveling'])->name('gayahidup.traveling.detail');
Route::get('/gayahidup/kuliner/{id}', [GayaHidupController::class, 'showKuliner'])->name('gayahidup.kuliner.detail');
        
Route::get('/gayahidup/berpakaian', [GayaHidupController::class, 'berpakaian'])->name('gayahidup.berpakaian');

and if you look my controller


    public function showGayaHidup($id)
{
    $gayahidup = GayaHidup::find($id);
    return view('pages.secnavbar.gayahidup.subhidup.berpakaian', compact('gayahidup'));
}

  
public function berpakaian()  
{  
    $berpakaian = GayaHidup::where('sub_categories', 'Berpakaian')->get();  // Ini mengambil data dari database
    return view('pages.secnavbar.gayahidup.subhidup.berpakaian', compact('berpakaian'));  // Ini mengirim variabel $berpakaian ke view
}

yea I know I use "showGayaHidup", because if I don't I get an error like this :

Call to undefined method App\Http\Controllers\GayaHidupController::showGayaHidup()

so what should I do? I am so clueless to connect it to this path resources\views\pages\secnavbar\gayahidup\subhidup\berpakaian.blade.php

tbh, I already admin's panel and send it to another blade. and it works perfectly. But not this one. So I am so confused this is the blade that show my data this is my admin's panel


Solution

  • I think there is a syntactical mistake,

    Route::get('/gayahidup/{id}'[GayaHidupController::class,'showGayaHidup'])>name('gayahidup.show');
    

    give -> instade of >

    >name('gayahidup.show');
    ->name('gayahidup.show');
    

    like below:

    Route::get('/gayahidup/{id}'[GayaHidupController::class,'showGayaHidup'])->name('gayahidup.show');