laravel 5.4 passport无法加载资源:服务器响应状态为500(内部服务器错误)

时间:2017-02-02 22:11:13

标签: laravel-5.4 laravel-passport

我安装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'
});

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

1 个答案:

答案 0 :(得分:0)

我发现我忘记添加使用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',
];

}