la_back/frontend/controllers/CategoryController.php

34 lines
669 B
PHP
Raw Permalink Normal View History

2023-11-21 19:51:44 +03:00
<?php
namespace frontend\controllers;
use common\models\Category;
/**
* Product controller
*/
class CategoryController extends BaseApiController
{
public function actionIndex()
{
return Category::find()
->select(['id', 'name'])
->all();
}
public function actionWithProducts()
{
return Category::find()
->select(['id', 'name'])
->with([
'products' => function (\yii\db\ActiveQuery $query) {
$query->select(['name', 'description', 'price', 'category_id']);
}
])
->asArray()
->all();
}
}