mardi 16 juillet 2019

Cannot access collection by properties Laravel 5.8

So I have three different arrays with the same length in the request and below is how I combine them into one collection:

$inputs = collect();
$keys = collect(['id', 'username', 'email']);
foreach ($request['ids'] as $index => $id) {
   $username = $request['usernames'][$index];
   $email = $request['emails'][$index];
   $inputs->push($keys->combine([$id, $username, $email]));
}

The result looks correct to me:

enter image description here

However, I cannot access the collection when I iterate over it:

foreach ($inputs as $input) {
    dd($input->id); // Property [id] does not exist on this collection instance.
}

This is the result of dd($input):

enter image description here

Any pointers on this problem? (Another short way to combine the arrays into one collection will also be appreciated!)

Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire