T
T
tarroma92021-10-01 11:42:28
Laravel
tarroma9, 2021-10-01 11:42:28

How in the created laravel collection, access information by property?

Good afternoon.
I'm trying to create my own collection with the necessary keys - values. Example:

$mass["word"] = "hello";
         $c = collect($mass);
         dump($c["word"]);

But if I needed just an array, then it was precisely he who was created. And I need to have access to the value through the property, for example:

$c->word;

Can this be done in a simple way?

It’s just that I don’t always have a value in the database, but sometimes there are several of them, and in the blade I have foreach, which works fine, even if there is one value in the collection. But if zero, then swears. So I decided to create my own collection object, which I will send in the controller, when With the same structure, access to the "table columns" as in the original. Only there values ​​​​will already be prepared for this case. $query->count() == 0;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question