Support the ongoing development of Laravel.io →
Session Views Testing

this is my loginAction that built session

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use App\Personal; use DB; use App\Quotation; use Session; class LoginController extends Controller { /** * Show the profile for the given user. * * @param int $id * @return Response */ public function loginAction(Request $request) { // $personal = new Personal; // echo $personal->name = $request->lastname; // echo $request->email; // echo $request->password; // exit(); $result = DB::table('personals') ->where('email', '=', $request->email) ->where('password', '=', md5(md5($request->password))); if($result->first()) { foreach ($result->get() as $key) { session()->put('firstname', $key->firstname); session()->put('personal_id', $key->personal_id); } // $personal_id = Session::all(); return redirect('profile'); } else { return redirect('login'); } } } this is the usercontroller that show the session <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use App\Personal; use Session; class UserController extends Controller { /** * Show the profile for the given user. * * @param int $id * @return Response */ public function getProfile() { echo $personal_id = session()->get('personal_id'); exit(); $profile = Personal::where('personal_id', $personal_id)->get(); return view('profile')->with('profile',$profile); } } already try the Session::get('personal_id'), but the result still NULL. Please advice.
Last updated 3 years ago.
0
$personal_id = session('personal_id');
echo $personal_id;
0

still not show the session,

they said to add this in my route:

Route::group(['middleware' => 'web'], function () { Route::post('loginAction', 'LoginController@loginAction');

Route::get('profile', [
	'as' => 'profile',
	'uses' => 'UserController@getProfile'
]);

});

also not show anything and show the error: TokenMismatchException in VerifyCsrfToken.php line 67:>scosec said:

$personal_id = session('personal_id');
echo $personal_id;
0

token mismatch means you didn't set the csrf token in the login form

0

It solved thanks to alainbelez, how to solve it:

Route::group(['middleware' => 'web'], function () { Route::get('login', function () { return view('login'); });

Route::post('loginAction', 'LoginController@loginAction');

Route::get('profile', [
	'as' => 'profile',
	'uses' => 'UserController@getProfile'
]);

});

do not forget to add input type hidden token

<form class="form-grey-fields" method="POST" action="loginAction"> <input type="hidden" name="_token" value="{!! csrf_token() !!}"> <div class="form-group"> <label class="sr-only">Email</label> <input type="email" name="email" placeholder="Email" class="form-control">
					</div>
					<div class="form-group m-b-5">
						<label class="sr-only">Password</label>
						<input type="password" name="password" placeholder="Password" class="form-control">
					</div>
					<div class="form-group form-inline text-left m-b-10 ">

						<div class="checkbox">
							<label>
								<input type="checkbox"><small> Remember me</small>
							</label>
						</div>
						<a class="right" href="#"><small>Lost your Password?</small></a>
					</div>
					<div class="text-left form-group">
						<button class="btn btn-primary" type="submit">Login</button>

					</div>
				</form>

Thanks

0

Sign in to participate in this thread!

Eventy

Your banner here too?

newbievii newbievii Joined 6 Jan 2016

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.

© 2025 Laravel.io - All rights reserved.