Reputation: 97
I have a pages controller.I wanna get some information stored in my db when /myshopping requested. This is my controller code :
public function myshopping()
{
$Buylist=DB::table('orders')->where('id','=',Auth::user()->id)->orderBy('oId','desc')->get();
$Bookinfo=DB::table('books')->where('bId','=',$Buylist->bId)->first();
return view('shop.myshopping',compact('Buylist','Bookinfo'));
}
Thank you very much.
Upvotes: 1
Views: 24
Reputation: 29278
Using->get()
on a QueryBuilder
returns a Collection
(fancy wrapper for PHP arrays), so $Buylist
is a group of records from your orders
table, as opposed to a single record.
If you change your logic to use ->first()
:
$Buylist=DB::table('orders')->where('id','=',Auth::user()->id)->orderBy('oId','desc')->first();
Then you can access $BuyList->bId
without issue (unless $BuyList
returns null
, but that's a different issue).
Upvotes: 1