亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

(API) Laravel 7 上不允許使用 tymon/jwt-auth 的 405 方法

(API) Laravel 7 上不允許使用 tymon/jwt-auth 的 405 方法

PHP
米琪卡哇伊 2023-10-01 17:09:08
所以我將從問題開始。我有與不記名令牌身份驗證一起使用的前端應用程序,該應用程序發送到我的后端。身份驗證的一切都很好,直到我想從我的路線獲取用戶數據Route::get('api/auth/me','Backend\AuthController@me');我收到錯誤 405 方法GET不允許我已經設置了回復路線GET我的路線:列表:+--------+----------+-------------------------+----------+------------------------------------------------------------+------------+| Domain | Method   | URI                     | Name     | Action                                                     | Middleware |+--------+----------+-------------------------+----------+------------------------------------------------------------+------------+|        | POST     | api/auth/login          | login    | App\Http\Controllers\Backend\AuthController@login          | api        ||        | POST     | api/auth/logout         | logout   | App\Http\Controllers\Backend\AuthController@logout         | api        ||        |          |                         |          |                                                            | auth:api   ||        | GET|HEAD | api/auth/me             | me       | App\Http\Controllers\Backend\AuthController@me             | api        ||        |          |                         |          |                                                            | auth:api   ||        | POST     | api/auth/refresh        | refresh  | App\Http\Controllers\Backend\AuthController@refresh        | api        ||        |          |                         |          |                                                            | auth:api   |+--------+----------+-------------------------+----------+------------------------------------------------------------+------------+我的 URI 選項卡: https://i.stack.imgur.com/aKLGu.png那么我的錯誤在哪里呢?請幫助我,我可能被這個問題困擾了 3 個多小時,我按照 tymondesign/jwt-auth 文檔中的每一步操作,但根本不起作用。
查看完整描述

1 回答

?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

我找到了問題的解決方案。這是我的錯誤,因為我的User.php模型中有拼寫錯誤


變更前型號:


<?php


namespace App;


use Illuminate\Foundation\Auth\User as Authenticatable;

use Illuminate\Notifications\Notifiable;

use Tymon\JWTAuth\Contracts\JWTSubject;


class User extends Authenticatable implements JWTSubject

{

    use Notifiable;


    /**

     * The attributes that are mass assignable.

     *

     * @var array

     */

    protected $fillable = [

        'name', 'email', 'password',

        'verified', 'balance', 'isAdmin',

    ];


    /**

     * The attributes that should be hidden for arrays.

     *

     * @var array

     */

    protected $hidden = [

        'password', 'verified',

    ];


    /**

     * getJWTCustomClaims

     *

     * @return mixed

     */

    public function getJWTCustomClaims()

    {

        return [];

    }


    /**

     * getJWTIdentifier

     *

     * @return array

     */

    public function getJWTIdentifier()

    {

        return $this->key;

    }

    

    /**

     * RelationShip between user, and user activation token

     *

     * @return void

     */

    public function verifyToken()

    {

        return $this->hasOne(UserVerification::class);

    }

}

變更后型號:


<?php


namespace App;


use Illuminate\Foundation\Auth\User as Authenticatable;

use Illuminate\Notifications\Notifiable;

use Tymon\JWTAuth\Contracts\JWTSubject;


class User extends Authenticatable implements JWTSubject

{

    use Notifiable;


    /**

     * The attributes that are mass assignable.

     *

     * @var array

     */

    protected $fillable = [

        'name', 'email', 'password',

        'verified', 'balance', 'isAdmin',

    ];


    /**

     * The attributes that should be hidden for arrays.

     *

     * @var array

     */

    protected $hidden = [

        'password', 'verified',

    ];


    /**

     * getJWTCustomClaims

     *

     * @return mixed

     */

    public function getJWTCustomClaims()

    {

        return [];

    }


    /**

     * getJWTIdentifier

     *

     * @return array

     */

    public function getJWTIdentifier()

    {

        return $this->getKey();

    }

    

    /**

     * RelationShip between user, and user activation token

     *

     * @return void

     */

    public function verifyToken()

    {

        return $this->hasOne(UserVerification::class);

    }

}

所以我將getJWTIdentifier()返回從更改$this->key為$this->getKey()


查看完整回答
反對 回復 2023-10-01
  • 1 回答
  • 0 關注
  • 112 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號