2
votes

I'm using Laravel 5.5.

My objective is to redirect to another method on the same controller to display a view with data.

class SeancesController extends Controller {

     ...

     public function getRecommandations(Request $request) {

          ...

          $data = [
               'recommandationAutresActiviteMemeDateHeure' => $recommandationAutresActiviteMemeDateHeure,
               'recommandationsMemeActiviteMemeHeure'      => $recommandationsMemeActiviteMemeHeure,
               'recommandationsMemeActiviteMemeDate'       => $recommandationsMemeActiviteMemeDate
          ];

          return redirect()->action('SeancesController@showRecommandations', $data);
     }

     public function showRecommandations(Request $request) {
          return view('listeRecommandations', $request->data);
     }
}

It is the right way to do this? Because I get this error :

InvalidArgumentException: Action App\Http\Controllers\SeancesController@showRecommandations not defined. in file /home/nicolas/public_html/M1_CSI/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 338

I need to use action because I use an ajax call to access at getRecommandations().

I used this doc : http://laraveldaily.com/all-about-redirects-in-laravel-5/.

I didn't add a route that points to showRecommendations on my routing file. It's a problem?

Thank's for help!

1
Do you have a route calling that exact method? You probably need to have a route like Route::get('foobar', 'SeancesController@showRecommandations'); for it to work.Marwelln
The method showRecommandations()? No I don't have define route.Royce
@Marwelln but with what I replace foobar because this route is not called via the urls.Royce
why you use redirect() ? you can simple call $this->showRecommandations($request); - but calling another method just for return view is not a good practiceRahul Reghunath
Because I'm using ajax and if I'm not using redirect() the view is return to the ajax call ... I hope I'm prettry clear.Royce

1 Answers

2
votes

I didn't add a route that points to showRecommendations on my routing file. It's a problem?

yes , it is a problem. because the redirector checks the routes that are assigned to the action and redirects the user to the route.