【问题标题】:laravel 5.4 passport Failed to load resource: the server responded with a status of 500 (Internal Server Error)laravel 5.4 护照加载资源失败:服务器响应状态为 500(内部服务器错误)
【发布时间】:2017-06-20 04:14:24
【问题描述】:

在我安装 laravel 5.4 并添加护照包后,我在控制台中收到这些错误

Failed to load resource: the server responded with a status of 500 (Internal Server Error)
app.js:11476 Uncaught (in promise) Error: Request failed with status code 500
    at createError (app.js:11476)
    at settle (app.js:11975)
    at XMLHttpRequest.handleLoad (app.js:11315)
http://localhost:8000/oauth/personal-access-tokens Failed to load resource: the server responded with a status of 500 (Internal Server Error)
app.js:11476 Uncaught (in promise) Error: Request failed with status code 500
    at createError (app.js:11476)
    at settle (app.js:11975)
    at XMLHttpRequest.handleLoad (app.js:11315)

这是我的 composer.josn

{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
    "php": ">=5.6.4",
    "laravel/framework": "5.4.*",
    "laravel/passport": "^2.0",
    "laravel/tinker": "~1.0"
},
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~5.0"
},
"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/"
    }
},
"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
},
"scripts": {
    "post-root-package-install": [
        "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ],
    "post-install-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postInstall",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "Illuminate\\Foundation\\ComposerScripts::postUpdate",
        "php artisan optimize"
    ]
},
"config": {
    "preferred-install": "dist",
    "sort-packages": true
}

}

这是我的 home.blade.php

@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
    <div class="col-md-8 col-md-offset-2">

            <passport-clients></passport-clients>
            <passport-authorized-clients></passport-authorized-clients>
            <passport-personal-access-tokens></passport-personal-access-tokens>
    </div>
</div>

@endsection

这是我的 app.js 文件

require('./bootstrap');



Vue.component(
  'passport-clients',
   require('./components/passport/Clients.vue')
);

Vue.component(
'passport-authorized-clients',
require('./components/passport/AuthorizedClients.vue')
);

Vue.component(
'passport-personal-access-tokens',
require('./components/passport/PersonalAccessTokens.vue')
);
Vue.component('example', require('./components/Example.vue'));

const app = new Vue({
el: '#app'
});

在我登录并尝试获取个人令牌后,我收到错误,当我看到控制台时,我发现内部服务器错误,我不知道我错过了什么

【问题讨论】:

    标签: laravel-5.4 laravel-passport


    【解决方案1】:

    我发现我忘记添加 use HasApiTokens;在类声明后的用户模型中

    namespace App;
    use Laravel\Passport\HasApiTokens;
    use Illuminate\Notifications\Notifiable;
    use Illuminate\Foundation\Auth\User as Authenticatable;
    
     class User extends Authenticatable
    {
    //that was missing 
    use HasApiTokens,Notifiable;
    
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];
    
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
    

    }

    【讨论】:

      猜你喜欢
      • 2013-04-16
      • 1970-01-01
      • 2018-01-22
      • 2014-11-24
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多