Home > Back-end >  Laravel 8 Route not defined even route is defined
Laravel 8 Route not defined even route is defined

Time:10-05

This error is comeup while i working on laravel 8

Route [product.details] not defined. (View: C:\xampp\htdocs\ecommerce\resources\views\livewire\shop-component.blade.php)

here is the route i made Route Page web.php

Route::get('/product/{slug}',DetailsComponent::class)->name('product.details');

this is line of view where i want that route View Page shop-component.balde.php

<a href="{{route('product.details',['slug'=>$product->slug]) }}" title="{{$product->name}}">

and this one is the Details Component code


namespace App\Http\Livewire;
use Livewire\Component;

class DetailsComponent extends Component
{
    public $slug;
    Public function mount($slug){
 
        $this->slug = $slug; 
    }

    public function render()
    {
     $product = Product::where('slug', $this->slug)->first();
    return view('livewire.details-component',['product'=>$product])->layout('layouts.base'); 
    }
}

I think this php code doesnot get route of product.details at the same time i create middleware file and define a different route in it this route is working in this page but not Product.details. Kindly help me i am stuck from 1 week here

CodePudding user response:

You can use

php artisan route:list

to show a list of registered routes - make sure it shows up there. If it doesn't, use

php artisan route:clear 

to clear Laravel's route cache

CodePudding user response:

It does not work because of your route. It's not write in the correct way. You have first to make your DetailsComponent::class is bracket then you have to give the name of the method you want to use in this class.

Route::get('/product/{slug}', [DetailsComponent::class, 'method name'])->name('product.details');

  • Related