Are @hareshc and @laurijirilla related? Same person?
Jul 28, 2022
3
Level 1
Auth login in Controller laravel 9
I am trying to login my user from a controller, and then redirect it to the necessary page.
My problem is that from my controller I can log in correctly, but when doing the redirect it doesn't preserve the session and I can't access the user information.
My Controller
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
class AuthUniqueController extends Controller
{
public function unique_login($user_id, $module)
{
$user = User::find($user_id);
Auth::guard('web')->login($user);
//dd(Auth::user()->id);
return redirect()->route($module);
}
}
(Auth::user()->id print correct user id);
My route:
Route::get('/requests', [MyController::class, 'my_function'])->name('requests');
And my_function in MyController:
public function my_function ()
{
dd(Auth::user()->id);
$user = Auth::user();
//return view('list_requests')->with('user_id', $user->id);
}
Here Auth::user()->id is null;
Please any ideas?
Please or to participate in this conversation.