I am sending a variable from controller to a view.
$message = "Thanks for Contacting";
return redirect('services')->with($message);
HTML
@isset ($message)
<a style="color: red;"> {{$message}} </a>
@endisset
But it shows en error, because when the first services
is loaded from this route
Route::get('/services', function () {
return view('services');
});
There's no variable,so it gives en error. Please let me know what I am missing?
You have to use it with @if, Try this:
@if(session()->has('message'))
<a style="color: red;"> {{ session('message')}} </a>
@endif
and also change your controller like this:
return redirect('services')->with('message', $message);