laravel - 在 Multi-Tenancy (hyn 包)laravel 中通过 API(使用护照)登录

标签 laravel laravel-5 multi-tenant laravel-passport

这是错误:

RuntimeException: Personal access client not found. Please create one. in file /var/www/html/pharmacy/vendor/laravel/passport/src/ClientRepository.php on line 94



这是我的登录功能:
 public function login(Request $request)
    {
        $request->validate([
            'email' => 'required|string|email',
            'password' => 'required|string',
            'remember_me' => 'boolean'
        ]);
        $credentials = request(['email', 'password']);
        if (!Auth::attempt($credentials))
            return response()->json([
                'message' => 'Unauthorized'
            ], 401);
        $user = $request->user();
        $tokenResult = $user->createToken('Personal Access Token');
        $token = $tokenResult->token;
        if ($request->remember_me)
            $token->expires_at = Carbon::now()->addWeeks(1);
        $token->save();
        return response()->json([
            'access_token' => $tokenResult->accessToken,
            'token_type' => 'Bearer',
            'expires_at' => Carbon::parse(
                $tokenResult->token->expires_at
            )->toDateTimeString(),
            'name' => Auth::user()->name,
            'email' => Auth::user()->email,
        ]);
    }

这是我的路由文件 api.php :
Route::group([
    'prefix' => 'auth'
], function () {
    Route::post('login', 'User\ParticipantAuth@login');


    Route::group([
        'middleware' => 'auth:api'
    ], function() {
        Route::get('logout', 'User\ParticipantAuth@logout');
        Route::get('user', 'User\ParticipantAuth@user');
    });
});

我只想在 Multi-Tenancy 中通过护照包 API 登录

我从 database/migration 复制了由护照包创建的所有迁移。并将其放入 database/migration/tenant保存其他迁移的文件夹。

最佳答案

在您的应用程序可以发布个人访问 token 之前,您需要创建一个个人访问客户端:

您需要创建一个 personal access token

php artisan passport:client --personal

关于laravel - 在 Multi-Tenancy (hyn 包)laravel 中通过 API(使用护照)登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54648886/

相关文章:

php - Laravel Scout & TNTSearch 如何结合关系型数据库使用?

Laravel 5 GET 正在运行,但 POST 方法不起作用

php - Laravel Notification - 在字符串上调用成员函数 routeNotificationFor()

asp.net-mvc - Windows Azure Multi-Tenancy

winforms - 我应该只使用 1 个数据库吗?

php - 查询多对多关系为一定值的所有记录

php - 正则表达式验证字母、点和破折号 Laravel

AngularJS 和 Laravel - CORS

php - Laravel 5.4 Eloquent 查询

asp.net - ASP.NET Web API 应用程序中的 Autofac Multi-Tenancy IoC 容器