Home > Net >  Pass multiple data with redirect()->route() in Laravel 9
Pass multiple data with redirect()->route() in Laravel 9

Time:10-10

I have this route in web.php:

Route::get('student/evaluation/{evaluation}', [EvaluationController::class, 'getEvaluationQuestions'])->middleware('auth')->name('student.questionsevaluation');

And in my controller I have this condition, where $questionWasCompleted is boolean

if($questionWasCompleted){

return redirect()->route('student.questionsevaluation', $evaluation)->with('message', 'Question answered.');
            
}

How can I pass the $questionWasCompleted parameter in this redirect()->route() ?

CodePudding user response:

Pass a second with() method in your controller like this:

return redirect()->route('student.questionsevaluation', $evaluation)
->with('message', 'Question answered.')
->with('question', $questionWasCompleted);

Alternatively, you can pass the both parameters in the same with() method like this:

return redirect()->route('student.questionsevaluation', $evaluation)
->with(['message' => 'Question answered.',
        'question' => $questionWasCompleted]);
  • Related