Laravel show Class签名不存在

时间:2018-01-06 09:16:27

标签: php laravel rest api laravel-passport

嗨我的Laravel Rest-API应用程序出现问题,每当我在Postman中访问localhost:8000 / api / login时就说

  

(1/1)ReflectionException类签名不存在

这是我的工匠路线:api / login的列表

  

POST | api / login | | App \ Http \ Controllers \ Api \ UserController @ login | API

这是我的api路线

<?php

use Illuminate\Http\Request;

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::post('oauth/token', '\Laravel\Passport\Http\Controllers\AccessTokenController@issueToken');


Route::group(['namespace' => 'Api'], function () {
    Route::post('/login', 'UserController@login');
});

这是我在Api文件夹中的UserController

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\User;
use Response;

class UserController extends Controller
{
    public function __construct()
    {
        $this->content = array();
    }

    public function login()
    {
        if (Auth::attempt(['email' => request('email'), 'password' => request('password')])) {
            $user = Auth::user();
            $this->content['token'] =  $user->createToken('Pizza App')->accessToken;
            $status = 200;
        } else {
            $this->content['error'] = "Unauthorised";
             $status = 401;
        }

        return response()->json($this->content, $status);    
    }
}

请帮助我,如果我试图在邮递员中测试我的Rest-Api,它一直在说

  

(1/1)ReflectionException   类签名不存在

1 个答案:

答案 0 :(得分:-1)

我认为您可以在laravel中使用示例进行自定义身份验证: https://www.minddevelopmentanddesign.com/blog/add-custom-api-authentication-to-laravel/