I am trying to simply iterate though a result set in laravel on the controller side. This is what I tried but I get the following error:
Cannot use object of type stdClass as array
Controller snippet:
$result = DB::select($query); foreach($result as $r){ echo $r['email']; }
I appreciate any help with this,
Thanks in advance!
You need to use it as an object:
$result = DB::select($query); foreach($result as $r){ echo $r->email; }
Or if for some reason you want to use it as array, you need to convert it first:
$result = DB::select($query)->toArray(); foreach($result as $r){ echo $r['email']; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With