Skip to content
Advertisement

unable to display session variables in a non-auth application

I’m trying to store and retrieve form data in laravel session. My app is non-auth, meaning users are not required to register, hence no authentication. After attempting to store form data in session, when I try to output it says:

“Trying to get property ‘name’ of non-object”

Why do I get this? Does laravel session by default work only with authentication? If not, how do I solve this? Is there a workaround? View code below, thanks.

controller

$request->session()->put('name', $request->input('name'));

blade

<input type="text" value="{{session()->get('name')->name}}" id="name" name="name" />

Advertisement

Answer

I guess it’s the ->name which is the issue…it looks like what you placed in the session was just a simple string containing a name, so why do you now expect that value to have a name property of its own?

You can just output the session value directly, without that extra bit:

value="{{session()->get('name')}}"
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement