Hey,
i have a question about a behavior that i don't understand.
In my ModelTrait i have an method defined that delivers products grouped by product category. i did it like that:
Code
- public static function getEnabledProductsByCategory()
- {
- /** @var Product $products */
- $products = self::query()->where('status = ?', [ Product::STATUS_ENABLED])->related('productCategory')->get();
- $result = null;
- foreach ($products as $product) {
- $result[$product->productCategory->id] = get_object_vars($product->productCategory);
- $result[$product->productCategory->id]['products'][] = $product;
- }
- return $result;
- }
- }
The type of the returning variable is an array.
In the Controller that renders my page i called it like this:
Code
- public function placeBookingAction()
- {
- $productsByCategory = Product::getEnabledProductsByCategory();
- /... other stuff (not necessary for this example)
- return [
- '$view' => [
- 'title' => "Sample",
- 'name' => 'lrmedien/extbooking:views/frontend/booking.php'
- ],
- '$data' => compact('productsByCategory', .... (other stuff) )
- ];
- }
When i take a look at the vue dev tools, productsByCategory is an Object now. I really don't know why. Where is the trick to works with the original array?
I hope somebody can help me...