Support the ongoing development of Laravel.io →
Authentication Session Views
Last updated 2 years ago.
0

Can you post the relevant controller and view code?

Last updated 2 years ago.
0

Here is my View code where i am checking that user has logged in or not.

<div class="ribbon">
			<nav>
				@if(Auth::check())
				<ul class="profile-nav">
					<li class="active"><a href="#" title="Dashboard">Hi, {{Auth::user()->name}}</a></li>																					
				</ul>
				<ul class="profile-nav">												
					<li class="active"><a href="/dashboard" title="Dashboard">Dashboard</a></li>					
				</ul>	
				<ul class="profile-nav">
					<li class="active"><a href="/logout" title="Logout">Logout</a></li>							
				</ul>						
				@else
				<ul><li class="active"><a href="#" title="Dashboard">Hi, Guest</a></li>											
				</ul>
				<ul>										
					<li class="active"><a href="#" id="showlogin" title="Login">Login</a></li>				

				</ul>
				<ul>				
					<li class="active"><a href="#" id="showreg" title="Settings">Register</a></li>
				</ul>
				@endif
				
			</nav>
		</div>

and here is my controller code where i log in user by accesspting request parameters. $username=e(Input::get('username')); $password=e(Input::get('password'));

	$credentials=array(
					'username'=>$username,
					'password'=>$password
					);

	if(Auth::attempt($credentials))
	{
		$user=User::where('username','=',$username)->first();
		Session::put('user',$user->name);
		$res = array ("res"=>"success");
		return Response::json($res, 200);
	}
	else
	{
		$res = array ("res"=>"fail");
		return Response::json($res, 401);
	}

in controller if i do Auth::check it returns true but in view it always returns false. also cookie is not persisting.

Last updated 2 years ago.
0

What if you pass the Auth data through to the view from the controller?

Last updated 2 years ago.
0

Actually session is not persisting. session data stores in filesystem but can's see session created in browser cookie as responce. no cookie is being created at all. even # laravel_session

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Hironate hironate Joined 1 Mar 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.