在我的视图中获取未定义的变量
WHERE b.salary > a.salary
//我的观点
public function confirm()
{
$data = Transaction::select('number','total','package')->where('user_id','=',\Auth::user_id()->id)->first();
return view('user.package',compact('data'));
}
答案 0 :(得分:2)
从\Auth::user_id()->id
更改为\Auth::user()->id
$data = Transaction::select('number','total','package')->where('user_id',\Auth::user()->id)->first();
通过两种方式获取当前的身份验证用户ID。
1.Auth::id();
2.Auth::user()->id
在您看来isset condition row is exist or not
@isset($data)
<center>
<h3 class="card-title"><b>You are about to buy {{$data->number}} package of {{$data->package}} for {{$data->total}}</b>
</h3>
</center>
@endif
答案 1 :(得分:0)
尝试使用-> get()代替-> first()
答案 2 :(得分:0)
使用此
use Auth;
public function confirm()
{
$data = Transaction::select('number','total','package')->where('user_id','=',Auth::user()->id)->first();
return view('user.package',compact('data'));
}
答案 3 :(得分:0)
尝试用auth()->user()->id
代替\Auth::user_id()->id
或 您可以使用
之类的口才关系$user->with('Transaction')->select('number','total','package')->first();