Support the ongoing development of Laravel.io →
Security Session
Last updated 1 year ago.
0

you can print it with

echo Session::get("message");
Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

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...

Last updated 1 year ago.
0

Hi, your

{{ $message or "" }}

is not working for me.

Last updated 1 year ago.
0

@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

Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

@SerdarSanri Good catch, thank you. Must be needing a new pair of glasses soon..

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

DevHack devhack Joined 19 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.