Missing required parameters for [Route: listele] [URI: {language}/{slug}]

Viewed 800

Missing required parameters for [Route: listele] [URI: {language}/{slug}] [Missing parameters: language, slug]. (View: C:\xampp\htdocs\efsane\resources\views\product\product.blade.php)

What is the reason I am getting such an error?

Blade file

@foreach ($categories as $p)
    <a href="{{route('listele') , app()->getLocale(), $slug }}"class="list-group-item">{{$p->name}}</a>
@endforeach

Route

 Route::group(['prefix' => '{language}'  ], function(){  

 Route::get('/{slug}' , 'App\Http\Controllers\ProductController@category')->name('listele');


 });

My Controller

      public function category($slug)


     {
  

     $category = Category::where('slug' , $slug )->first();
     $data['category'] = $category;

     $data['categories'] = Category::inRandomOrder()->get();


     $data['posts'] = Post::where('category_id' , $category->id)->orderBy('id',  'DESC')->paginate(10);
     return view('product.kategorilist' , $data );
     }
1 Answers

You will need to put the route paramter values in an array and put that array in your route method route('listele', [app()->getLocale(), $p->slug]).
You will also need to access the category slug from the object so you have to use $p->slug.

@foreach ($categories as $p)
 <a href="{{route('listele', [app()->getLocale(), $p->slug])}}"
class="list-group-item">{{$p->name}}</a>
@endforeach

--EDIT

There was also the </a> endtag missing

--EDIT2

Your controller method defines only the $slug parameter. But you are defining a prefix in your route for the $language parameter and the route itself defines the $slug parameter.

You have to simply add another parameter called $language to your controller method.

      public function category($language, $slug) { .... }

In your case the language value was assigned to the slug variable and therefore no categroy was found (null is set). If you want to access an attribute of a null object you have a problem.

I would add a check to ensure $category is not null.

public function category($language, $slug) {

$category = Category::where('slug' , $slug )->first(); 
  if(is_null($category)){
    return redirect()->back();
  }
 ....
 }
Related