【发布时间】:2019-05-11 23:46:49
【问题描述】:
我正在尝试创建一个中间件,如果在标识表上未找到任何数据,该中间件会将用户重定向到验证页面,但我不断得到 if 语句的逻辑错误
我已经尝试将$request->user()->identification->()has('user_id) 作为我的 if 语句
//从我的标识中间件,我有这个;
<?php
namespace App\Http\Middleware;
use Closure;
class Identification
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (! $request->user()->identification()->verified) {
return redirect('identification');
}
return $next($request);
}
}
我希望这应该返回为真并继续到下一页,因为我已经有属于该用户的标识表中的数据
但我收到此错误
ErrorException (E_NOTICE) 未定义属性: Illuminate\Database\Eloquent\Relations\HasOne :: $verified
【问题讨论】:
-
ErrorException (E_NOTICE) 未定义属性:Illuminate\Database\Eloquent\Relations\HasOne :: $verified
-
请在此处发布您的型号代码(关系方法)。
-
public function identification(){ return $this->hasOne('App\Identification'); } -
public function user(){ return $this->belongsTo('App\User'); }