Search code examples
phplaravelhttp-redirectcontroller

Redirect to laravel controller action - action not defined


I am trying to redirect the page from a controller to an action in another controller in Laravel 5.3. The error returned is:

InvalidArgumentException in UrlGenerator.php line 605:
Action App\Http\Controllers\StartChoosingController@index not defined.

My codes are as follows:

HomeController.php: enter image description here

StartChoosingController.php: enter image description here

As I looked over the internet to find an answer I could discover that my problem might be because of not having used the proper namespacing:
https://stackoverflow.com/questions/29822302/laravel-action-not-defined

Would you please tell me how and what to add to the namespace of use part of my code to fix the issue? Thank you very much in advance.


Solution

  • If you're using Route::resource() for controller routes, try to change index() method to showAll() and add parameter:

    public function showAll($userTableData)
    

    And use it:

    redirect()->action('StartChoosingController@showAll', ['userTableData' => $user_table_data]);
    

    Also, you'll need to define new route:

    Route::get('show-all/{userTableData}', 'StartChoosingController@showAll')
    

    If userTableData is not a string, but an object, you should pass data with post method and hidden inputs.