Reputation: 139
In my controller I have the I have a redirect if a condition is met and want to use the page message to convey the reason for the redirect. However, I can't find a way to send a line break from the controller to the bootstrap message area so that it displays multiple lines. I can find many answers for what to do in the blade, mainly escaping the HTML with {! markup !}
, but that doesn't work in the controller where I'm sending the message.
Here's my controller code:
$message = "Nothing to do. </br>You must first enter account data to generate a report";
return redirect()->route('admin.home')->with('message', $message);
The "</br>
" tag is displayed. I've tried "/n
" and "
" to no avail, they don't render but also no line break. I need to send more detailed messages depending on the condition for redirecting which won't work if everything has to go on one message line.
I'm using Laravel 5.5 in XAMPP (PHP 7) on Windows 10, Chrome for dev browser, VS Code for coding.
Any suggestions?
Upvotes: 0
Views: 6727
Reputation: 139
SOLVED: Part of my problem was that "message" is a default variable name that automatically gets displayed in the message area of a bootstrap page, so when I tried using my own code in the blade I would get both the automatic message display as well as my own. By changing from the default name "message" I can pull the session variable in the blade and display it without getting two messages. It's identical to the default message, but now I can escape the markup and get my line breaks. New code as follows:
Controller:
$message = "Nothing to do. </br>You must first enter account data to generate a report";
return redirect()->route('admin.home')->with('special_message', $message);
Blade:
@if(Session::has('special_message'))
<p class="alert alert-info">{!! Session::get('special_message') !!}</p>
@endif
Upvotes: 1
Reputation: 856
Have you tried {!! $message !!} in your blade template?
Just be sure that your return statement cannot contain any user inputted HTML as this may allow XSS.
Please see the following documentation on "displaying unescaped data"
https://laravel.com/docs/5.5/blade#displaying-data
Upvotes: 3