HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/file.nepi.ir/common/Search/Controllers/NormalizedModelsController.php
<?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->search($query);
        }

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

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