Send parameter from one route to another

2

I want to send a variable from one route to another, to display this variable in the view, use example:

public function create(ExamRequest $request)
{
    Exam::create( $request->all() );
    $message = 'A avaliação "'.$request->input('name').'" foi registrada!';
    return redirect()->route('exams')->withMessage($message);
}

The route exams in my case calls a view , and I try to display the parameter in the same way:

<div class="row text-success text-center">
    {{ isset($message) ? $message : '' }}
</div>

But nothing ever appears, how can I send a parameter to another route?

PS: I know that with view works, example view('exams')->withMessage($message); , but in case it does not change the browser link and I want this link to crash. p>     

asked by anonymous 09.01.2017 / 18:35

2 answers

2

There is nothing wrong with your redirection.

In fact, the with ¹ method stores the value passed temporarily in the session until it is accessed. This is called "Session Flash" in most frameworks.

1 - Both in the normal call of the method and in the magic call of the with method the data is sent to the flash

To access the value, you would have to do so in the view:

 {!! session('message') !!}
    
09.01.2017 / 18:42
2
return redirect()->route('exams')->with(['message' => $message]);

If an action for the exams link is configured in the routes file, it will work.

<div class="row text-success text-center">
    {!! (Session::has('message')) ? Session::get('message') : '' !!}
</div>
    
09.01.2017 / 18:39