【发布时间】:2017-08-10 15:34:04
【问题描述】:
当我从邮递员测试我的 REST API 时,它给了我错误
Trying to get property of non-object
因为邮递员没有会话。如果有浏览器,则创建会话但不在邮递员中。任何人都可以提供Auth::user()的替代解决方案
这是我的路线
Route::post('playlist/{id}/follow', 'PlaylistController@follow');
这是我的代码 sn-p。
public function follow($id)
{
$user = $this->model->findOrFail($id);
if ($user->id != Auth::user()->id) {
Auth::user()->followedUsers()->attach($id);
}
}
【问题讨论】:
-
你用
auth:api保护你的路线吗? -
不,我没有保护。
-
您能否说明您要使用
apisession 还是websession? -
是的,我想使用 api 会话。
-
你需要它来让 Auth 中间件处理其余的事情。