37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Foundation\Bus\DispatchesJobs;
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class Controller extends BaseController
|
|
{
|
|
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
|
|
|
public function index(Request $request, Bool $paginate = true) {
|
|
try {
|
|
$route = explode('.', $request->route()->getName());
|
|
$model = $route[1];
|
|
$class = 'App\\Models\\' .ucfirst($model);
|
|
|
|
$errors = [];
|
|
|
|
$instances = $class::fetchAll($request, $paginate);
|
|
|
|
foreach ($instances as $i) {
|
|
$i->setDataTree();
|
|
}
|
|
|
|
return response()->json([$model => $instances, 'status' => 'OK'], 200);
|
|
} catch (\Exception $e) {
|
|
Log::debug($e->getMessage() . ' ' .$e->getFile() . ' ' .$e->getLine());
|
|
return response()->json(['status' => 'ERROR', 'message' => $e->getMessage(), 'errors' => $errors], 404);
|
|
}
|
|
}
|
|
}
|