Sajid
Sajid

Reputation: 11

How to remove default index action on controller from laravel 5.5

I am using Laravel 5.5 version. I defined my routes in the routes.php file. like this:-

$router->group(['middleware' => 'auth'], function($router) {
    $router->resource('/route-name', 'myController@myMethodName'); 
}); 

But when I run my application laravel gives error:-

Method [myMethodName@index] does not exist on [App\Http\Controllers\myController].

It is by default put index action after my defined action in the routes.
It is working fine in the laravel 5.3 version. Please solve my problem..

Upvotes: 1

Views: 570

Answers (2)

Ashutosh Sharma
Ashutosh Sharma

Reputation: 432

By Default resource Request create CRUD requests in routes. For the following methods in Controller.

  • Index(GET)
  • Create(GET)
  • Store(POST)
  • Show(GET)
  • edit(GET)
  • Update(PUT/PATCH)
  • Delete(DELETE)

You can't pass method name in resource route.

If you want to override any of them. you have to write new one route below the resource Route. Like

Route::get('url','Controller@newMethod');

And Change the method name in Controller with newMethod
For more detail check laravel documents

Upvotes: 0

Sand Of Vega
Sand Of Vega

Reputation: 2416

Try this as @devk told in comment:

$router->get('/route-name', 'myController@myMethodName');

Upvotes: 1

Related Questions