JFIFxxC      C  " }!1AQa"q2#BR$3br %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz w!1AQaq"2B #3Rbr{ gilour

File "NormalizedModelsController-20260314142049.php"

Full Path: /home/markqprx/iniasli.pro/Controllers/NormalizedModelsController-20260314142049.php
File size: 1.15 KB
MIME-type: text/x-php
Charset: utf-8

<?php

namespace Common\Search\Controllers;

use Common\Core\BaseController;
use Illuminate\Database\Eloquent\Model;

class NormalizedModelsController extends BaseController
{
    public function show(string $modelType, int $modelId)
    {
        $namespace = modelTypeToNamespace($modelType);
        $with = request('with') ? explode(',', request('with')) : [];

        $model = app($namespace)->findOrFail($modelId);
        $model->load($with);

        $this->authorize('show', $model);

        return $this->success(['model' => $model->toNormalizedArray()]);
    }

    public function index(string $modelType)
    {
        $namespace = modelTypeToNamespace($modelType);
        $query = request('query');
        $with = request('with') ? explode(',', request('with')) : [];

        $this->authorize('index', $namespace);

        $model = app($namespace);
        if ($query) {
            $model = $model->mysqlSearch($query);
        }

        $results = $model
            ->take(15)
            ->get()
            ->load($with)
            ->map(fn(Model $model) => $model->toNormalizedArray());

        return $this->success(['results' => $results]);
    }
}