HEX
Server: nginx/1.18.0
System: Linux test-ipsremont 5.4.0-214-generic #234-Ubuntu SMP Fri Mar 14 23:50:27 UTC 2025 x86_64
User: ips (1000)
PHP: 8.0.30
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/ipsremont-demo/app/Http/Controllers/SpecificationController.php
<?php


namespace App\Http\Controllers;


use App\Http\Requests\Device\IndexRequest;
use App\Http\Requests\IdRequest;
use App\Http\Requests\Specification\SearchRequest;
use App\Models\Device;
use App\Models\Permission;
use App\Services\Category\CategoryService;
use App\Services\Device\DeviceService;

class SpecificationController extends Controller
{

    protected string $permission = Permission::parts;

    public DeviceService $service;
    public CategoryService $serviceCategory;

    public function __construct()
    {
        parent::__construct();

        $this->service = new DeviceService();
        $this->serviceCategory = new CategoryService();
    }

    public function index(IndexRequest $request)
    {
        if ($request->external_id || $request->name) {
            $external_id = ($request->external_id) ? $request->external_id : '';
            $name = ($request->name) ? $request->name : '';

            return redirect()->route('specifications.categories.devices', ['external_id' => $external_id, 'name' => $name]);
        }

        $categories = $this->serviceCategory->search_specifications(new \App\Http\Requests\Category\IndexRequest());

        $routes = [];
        foreach ($categories as $category) {
            $routes[route('specifications.categories.list', $category->getCode())] = __($category->getName());
        }

        return view('specifications.index', compact('routes'));
    }

    public function list(IndexRequest $request)
    {
        $data = $this->service->search_specifications($request);

        if (count($data) == 1) {
            return redirect()->route('specifications.categories.device', $data[0]->external_id);
        }

        $category = 'specifications.devices';
        if ($request->id) {
            $category = CategoryService::getByCode($request)->name;
        }

        return view('specifications.devicelist', compact('data', 'category'));
    }

    public function devices(IdRequest $request)
    {
        $device = $this->service->getDevice($request);

        $category = CategoryService::getByDeviceCode($device->external_id);

        return view('specifications.device', compact('device', 'category'));
    }

    public function download(IdRequest $request)
    {
        $pathToFile = storage_path() . "/app/public/specifications/$request->id";

        return response()->download($pathToFile);
    }

    public function ajaxSearch(SearchRequest $request)
    {
        $items = $this->service->searchDevicesAjax($request->term);

        return response()->json(compact('items'));
    }

}