rest api expand, url params

This commit is contained in:
Kavalar 2024-10-07 11:54:10 +03:00
parent 04da662275
commit c7e113e325
2 changed files with 8 additions and 5 deletions

View File

@ -119,11 +119,11 @@ class Request
/**
* Возвращает GET - параметр.
* @param string $param Параметр.
* @param mixed $defaultValue Значение если, параметр не передан.
* @param string|null $param Параметр.
* @param mixed|null $defaultValue Значение если, параметр не передан.
* @return mixed
*/
public function get($param = null, $defaultValue = null): mixed
public function get(string $param = null, mixed $defaultValue = null): mixed
{
if (is_null($param)) {
return $_GET;

View File

@ -36,9 +36,12 @@ class RestController
#[NoReturn] public function actionView($id): void
{
$expand = $this->expand();
$request = new Request();
$expandParams = explode( ",", $request->get('expand') ?? "");
$model = $this->model->where("id", $id)->first();
if ($expand){
$model->load($expand);
$finalExpand = array_intersect($expandParams, $expand);
if ($finalExpand){
$model->load($finalExpand);
}
$res = [];
if ($model){