在API FormRequest中使用laravel Auth :: check()

时间:2017-08-07 12:08:39

标签: laravel

我为我的应用程序创建了一个API,然后在应用程序内部开始使用它。也就是说,我的显示,编辑等刀片视图将ajax请求发送到在routes / api.php中配置的路由。现在我需要在API路由表单请求中执行Auth :: check(),但发现它在" api"下不可用。中间件。有什么方法可以挽救我的情况?在API中查找登录用户的最简单方法是什么?

编辑: 这是我在api表单请求中尝试做的。

public function authorize()
{
    $slot = Slot::find($this->route('slot'));
    // If administrator is logged in all is good.
    // If slot is free its also ok.
    return ( Auth::check() || $slot->isAvailable() );
}

1 个答案:

答案 0 :(得分:1)

使用auth middleware

Route::group(['middleware' => 'auth'], function () {

    // Only authenticated users allowed here

});
相关问题