How about function logout? i've try with $token = $request->user()->tokens(); $token->revoke(); but still, it doesn't work. Any solution?
@mdaohinuzzaman6 күн бұрын
token,, not tokens
@Arya-si3ur2 ай бұрын
when i paste the functions in the "AuthController.php" file it gives me error Undefined method 'attempt'.intelephense(P1013) Undefined method 'user'.intelephense(P1013) do you have any soulution?
@ryansumbele35528 күн бұрын
please did you solve this problem? i'm facing thesame issue, if you replace 'auth()' with 'Auth', it kind of solves that problem, but then i run into another error, 'undefined method createToken' in login functon
@Arya-si3ur8 күн бұрын
@@ryansumbele3552 i downloaded (laravel idehelper) and it worked
@ryansumbele35528 күн бұрын
i found a solution , your register and login function in your authcontroller should look like this: public function register(Request $request) { $registerData = $request->validate([ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed' ]); $registerData['password'] = Hash::make($request->password); $user = User::create($registerData); $accessToken = $user->createToken('authToken')->accessToken; return response()->json([ 'user' => $user, 'access_token' => $accessToken, ],201); } public function login(Request $request) { $loginData = $request->validate([ 'email' => 'required|string|email', 'password' => 'required|string', ]); $user = User::where('email', $loginData['email'])->first(); if (!$user || !Hash::check($loginData['password'], $user->password)) { return response()->json(['message' => 'Invalid credentials'], 401); } $accessToken = $user->createToken('authToken')->accessToken; return response()->json([ 'user' => $user, 'access_token' => $accessToken, ],201); }