How does laravel generate token when using JWT?

look at this link on the site Laravel5.5 installation JWT
I have two questions to ask: why do you put the User model directly into the app directory in the section configuring Model and Controller at the beginning of the
article? Shouldn"t it be under the Models directory?
and don"t all User models inherit Model to write class User extends Model ?
Why does he write class User extends Authenticatable implements JWTSubject here?
so you can"t inherit Model.

second question how is the $token of the login method in AuthController generated? This $token is finally returned to the front-end TOKEN, but I think this $token did not write how to get ah? My test is always prompting Undefined variable: token can you explain it? Thank you

<?php
namespace App\Http\Controllers;

use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;

class AuthController extends Controller
{
    public function __construct()
    {
        $this->middleware("auth:api", ["except" => ["login"]]);
    }

    public function login()
    {
        $credentials = request(["email", "password"]);

        if (! $token = auth()->attempt($credentials)) {
            return response()->json(["error" => "Unauthorized"], 401);
        }

        return $this->respondWithToken($token);
    }
May.25,2022

first question: there is no uniform standard in which directory the User model is placed, according to your personal habits, and laravel comes with no Models folder.
second question: the inherited Authenticatable is the code use Illuminate\ Foundation\ Auth\ User as Authenticatable . If you enter the Illuminate\ Foundation\ Auth\ User class, we will see the code class User extends Model , so the User model inherits Model, oh,
. The third problem is implemented by JWT. I'm not very clear about this. I don't know if Daniel can supplement


. The

auth ()-> attempt method returns token directly if the information is verified successfully. If true is returned, the configuration file config/auth.php may not have been modified, because laravel determines whether the user authenticates to use session or jwt through the configuration file. If you return false , there is a problem with the passed array.

on the second question, a syntax trick is used. $token is assigned in the if conditional statement. For token generation details, you can search for the jwt token keyword.

if (! $token = auth()->attempt($credentials)) {
    return response()->json(['error' => 'Unauthorized'], 401);
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ebe2ec-29b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ebe2ec-29b0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?