我有此密码
$tempid = DB::table('local_founders')->select('entry_by')->where('founder_id', $id)->get();
if($tempid[0] != Auth::user()->id){
return Redirect::to('founder')->with('messagetext','Record Not Found !')->with('msgstatus','error');
}
但导致此错误:
stdClass类的对象无法转换为int
答案 0 :(得分:0)
$tempid = DB::table('local_founders')->select('entry_by')->where('founder_id', $id)->get();
返回一个集合,如果需要第一个元素,则更改为:
$temp = DB::table('local_founders')->select('entry_by')->where('founder_id', $id)->first()
现在 $ temp 是一个stdClass,之后您可以像访问其他任何stdClass对象一样轻松地访问它,如下所示:$temp->entry_by
所以我认为您必须按照以下步骤更改代码:
$local_founder = DB::table('local_founders')->select('entry_by')->where('founder_id', $id)->first();
if($local_found->entry_by != Auth::user()->id){return Redirect::to('founder')->with('messagetext','Record Not Found !')->with('msgstatus','error');}