you can print it with
echo Session::get("message");
SerdarSanri said:
you can print it with
echo Session::get("message");
w00t that happened :-
{{ Session::get('message') !== null ? Session::get('message') : '' }}
Is using Session::get('message')
the only alternative ?
Thanks
You could do {{ $message or "" }}
If $message is set, and has a value, it will write out that value. If not it will write out nothing ""
If you don't have the or set , it will throw a variable undefined exception...
Hi, your
{{ $message or "" }}
is not working for me.
@getio, Weird. I just checked and I can confirm it works. Basically the or is saying if $message is set and has a value echo that else echo nothing ("")
I just did a quick test as such. A default route,
//A route with a message variable passed
Route::get('/', function() {
return View::make('dummy')->with('message', 'Some message here');
});
And in my dummy.blade.php view file
{{ $messsage or 'Default View'}}
With this, I get the output 'Some message here'.
If i elimiate the with clause and just pass
return View::make('dummy')
then the output from the view is 'Default View'.
And with
{{ $message or "" }}
I get the variable printed if it is passed, or nothing printed if its not passed...
I've sometimes found laravel takes a while (more than a few refreshes) for blade to compile the new changes...meh...it works though
abhiyanp said:
@getio, Weird. I just checked and I can confirm it works. Basically the or is saying if $message is set and has a value echo that else echo nothing ("")
I just did a quick test as such. A default route,
//A route with a message variable passed Route::get('/', function() { return View::make('dummy')->with('message', 'Some message here'); });
And in my dummy.blade.php view file
{{ $messsage or 'Default View'}}
With this, I get the output 'Some message here'.
If i elimiate the with clause and just pass
return View::make('dummy')
then the output from the view is 'Default View'.
And with
{{ $message or "" }}
I get the variable printed if it is passed, or nothing printed if its not passed...
I've sometimes found laravel takes a while (more than a few refreshes) for blade to compile the new changes...meh...it works though
I think you are missing that he is using Redirect instead of View::make
if you were rendering a view direcly you can access data with $variable name, but because you are using Redirec, the data you pass to Redirect class "with" method is only accessible with Session. Or instead of passing message you can pass ->withErrors() and can ready validation errors on the view.
take a look at
http://laravel.com/docs/4.2/validation#error-messages-and-views
@SerdarSanri Good catch, thank you. Must be needing a new pair of glasses soon..
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community