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);
}