S
S
semki0962019-04-13 21:17:42
Twig
semki096, 2019-04-13 21:17:42

When is it better to work with objects, and when with arrays, using an example?

For example, working with eloquent, I get a collection . Then I pass this object to the template. I use Twig and it would probably be more convenient to work with an array rather than an object. Am I right in thinking that before passing data from the controller to the view, the object must be converted to an array? And the second question. It is not converted to an array, apparently because dependencies interfere? How then to be?
$products=Product::with('colors')->get();

$products=Product::with('colors')->get();
$prod = $products->toArray();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
isEmpty, 2019-04-13
@isEmpty

there is no need to pass an array to views, it is much more convenient to work with an object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question