If you use the standard auth process in laravel, you can retrieve the current user with Auth::user()(or Auth::id(), if you only want the id).
So yes it's possible with session, but it's almost native. https://laravel.com/docs/5.6/authentication
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
LoginController.php
public function login(Request $request)
{
$this->validate($request, [
'username' => 'required|min:6|max:15',
'password' => 'required|min:8|max:16',
]);
if(auth()->attempt(['username' => request('username'), 'password' => request('password')]))
{
$id = User::find($id);
$request->session()->put('id', $id);
return redirect('/seller');
}
session()->flash('flash', 'username atau password anda salah atau belum terdaftar. Mohon mendaftarkan diri di link di bawah ini jika belum.');
return redirect('/login');
}
Check this Login Controller. I actually want to make the program remember the id of who is login. Can you do that? Is that using what's called session?
Check this part of the codes:
if(auth()->attempt(['username' => request('username'), 'password' => request('password')]))
{
$id = User::find($id);
$request->session()->put('id', $id);
return redirect('/seller');
}
Is that correct? Since you are only login using username and password. and I need to know the $id (primary key) and remember it.
I am going to retrieve the id to retrieve other data after login based on the user_id or id.
If you use the standard auth process in laravel, you can retrieve the current user with Auth::user()(or Auth::id(), if you only want the id).
So yes it's possible with session, but it's almost native. https://laravel.com/docs/5.6/authentication
Please or to participate in this conversation.