skip to Main Content

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.')
->with('question', $questionWasCompleted);
            
}

How can I get the value of $questionWasAnswered to know if it’s true or false in the view file?

I tried with {{$questionWasCompleted}} in view file but it not works.

3

Answers


  1. You are not showing what data you are sending to the view file. But typically a Route should send you to a Controller action, and inside the controller action (ex. index) you return the view you want to show and pass the data. Or maybe redirect to another route. Anyway in this case to be able to see the data to the view you should place code below inside the Controller action:

    return view('view_file_name', ['message'=> 'Question answered.', 'question' => $questionWasCompleted]) 
    

    and then you should be able to see the $message and $question values inside the view file using {{}} like: {{ $message }}. And the value of the $questionWasCompleted should be available using {{ $question }}

    Login or Signup to reply.
  2. first of all check if your view file is in blade format (example: view.blade.php) then try {{ $question }}

    Login or Signup to reply.
  3. with method of redirect() obj saves the key in session of requested user
    so in your blade file you can access it like this :

    {{  session('question') }}
    

    Also notice that first argument of with() method ( for example ‘message’) is the key and the second argument is ( for example ‘Question answered.’) is your value , for accessing the value you should use the key in your blade file .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search