Search code examples
laravel-bladebootstrap-5laravel-11laravel-resourcelaravel-service-container

Laravel Resource route is not holding any parameter on route list


GET|HEAD        blogs ..................................................................................... blog.index › Blog\BlogController@index  
  POST            blogs ..................................................................................... blog.store › Blog\BlogController@store  
  GET|HEAD        blogs/create ............................................................................ blog.create › Blog\BlogController@create  
  GET|HEAD        blogs/{} .................................................................................... blog.show › Blog\BlogController@show  
  PUT|PATCH       blogs/{} ................................................................................ blog.update › Blog\BlogController@update  
  DELETE          blogs/{} .............................................................................. blog.destroy › Blog\BlogController@destroy  
  GET|HEAD        blogs/{}/edit ............................................................................... blog.edit › Blog\BlogController@edit  

Hello, I am trying to make an blog feature in my site. And I have created an migration table without soft delete feature. and then i have created A model and then i have created a controller using php artisan make:controller Blog/BlogController --model=Blog --resource.

// __________Route for blogs
Route::prefix('blogs')->name('blog.')->group(function () {
    Route::resource('', BlogController::class);
});

That's how i called the route. Everything was working well. The index, create, store method. But as you can see there is parameter passing inside the store route. and giving me 404 error if I call the route also. Please help if anybody knows about the problem.

I have tried to invoke the show method from controller via resource route like <a href="{{ route('blog.show', $blog) }}" class="btn btn-secondary">Read More</a>. but rising 404


Solution

  • It is because of the first empty parameter in Route::resource(). The first parameter should not be empty.

    Route::resource('blogs', BlogController::class);
    

    It will automatically register name and prefix.