Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
gilour
/
foundation
/
src
/
Search
/
Controllers
:
NormalizedModelsController.php
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?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]); } }