🎉 سال نو، مهارت نو، مشاوره رایگان نقشه راه برنامه نویسی (آفر ویژه ثبت نام قبل از افزایش قیمت 🔥)
۰ ثانیه
۰ دقیقه
۰ ساعت
۱ Mahdi
error Undefined method factory & refresh in AuthController.php
جامعه لاراول ایجاد شده در ۲۳ آبان ۱۴۰۱

سلام

بعد از ساخت کلاس


namespace App\\Http\\Controllers;
use Illuminate\\Support\\Facades\\Auth;
use App\\Http\\Controllers\\Controller;
class AuthController extends Controller
{
    /**
     * Create a new AuthController instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth:api', ['except' => ['login']]);
    }
    /**
     * Get a JWT via given credentials.
     *
     * @return \\Illuminate\\Http\\JsonResponse
     */
    public function login()
    {
        $credentials = request(['email', 'password']);
        if (! $token = auth()->attempt($credentials)) {
            return response()->json(['error' => 'Unauthorized'], 401);
        }
        return $this->respondWithToken($token);
    }
    /**
     * Get the authenticated User.
     *
     * @return \\Illuminate\\Http\\JsonResponse
     */
    public function me()
    {
        return response()->json(auth()->user());
    }
    /**
     * Log the user out (Invalidate the token).
     *
     * @return \\Illuminate\\Http\\JsonResponse
     */
    public function logout()
    {
        auth()->logout();
        return response()->json(['message' => 'Successfully logged out']);
    }
    /**
     * Refresh a token.
     *
     * @return \\Illuminate\\Http\\JsonResponse
     */
    public function refresh()
    {
        return $this->respondWithToken(auth()->refresh());
    }
    /**
     * Get the token array structure.
     *
     * @param  string $token
     *
     * @return \\Illuminate\\Http\\JsonResponse
     */
    protected function respondWithToken($token)
    {
        return response()->json([
            'access_token' => $token,
            'token_type' => 'bearer',
            'expires_in' => auth()->factory()->getTTL() * 60
        ]);
    }
}

refresh و factory این دوتا رو vscode ناشناخته میزنه

مربوط به متد refresh

  • و متد respondWithToken هستند
'expires_in' => auth()->factory()->getTTL() * 60
return $this->respondWithToken(auth()->refresh());

دو خط بالا

Mahdi ۲۳ آبان ۱۴۰۱، ۱۳:۴۱