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/Models/MovementThroughWarehouses.php
<?php

namespace App\Models;

use App\Helpers\UserHelper;
use App\Models\Repair\Repair;
use App\Models\Service\Service;
use App\Traits\My;
use App\Traits\Sortable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;

/**
 * @property int $id
 * @property string $repair_id
 * @property string $part_id
 * @property string $amount
 * @property string $type
 * @property string $service_id
 * @property string $created_at
 * @property string $updated_at
 * @property string $deleted_at
 *
 * @property Repair $repair
 * @property Part $part
 * @property Service $service
 */
class MovementThroughWarehouses extends BaseModel
{

    use SoftDeletes, Sortable, My;

    protected $table = 'movement_through_warehouses';

    protected $fillable = [
        'part_id',
        'repair_id',
        'amount',
        'type',
        'service_id',
    ];

    protected static $labels = [
        'part_id' => 'movement.part_id',
        'repair_id' => 'movement.repair_id',
        'amount' => 'movement.amount',
        'type' => 'movement.type',
        'created_at' => 'movement.created_at',
    ];

    public static function columns(): array
    {
        return [
            'fields' => [
                [
                    'displayName' => 'movement.repair_id',
                    'field' => 'repair_id',
                    'sort' => true,
                    'sortType' => 'asc',
                    'class' => 'w-100px',
                ],
                [
                    'displayName' => 'movement.part_id',
                    'field' => 'part_id',
                    'sort' => true,
                    'sortType' => 'asc',
                    'class' => 'w-100px',
                ],
                [
                    'displayName' => 'movement.warehouseAmounts',
                    'field' => 'amount',
                    'sort' => true,
                    'sortType' => 'asc',
                    'class' => 'w-100px',
                ],
                [
                    'displayName' => 'movement.amount',
                    'field' => 'amount',
                    'sort' => true,
                    'sortType' => 'asc',
                    'class' => 'w-100px',
                ],
                [
                    'displayName' => 'movement.created_at',
                    'field' => 'created_at',
                    'sort' => true,
                    'sortType' => 'asc',
                    'class' => 'w-100px',
                ],
            ],
            'sortDefault' => [
                [
                    'field' => 'id',
                    'sort' => 'desc',
                ],
            ],
        ];
    }

    public function repair(): BelongsTo
    {
        return $this->belongsTo(Repair::class);
    }

    public function part(): BelongsTo
    {
        return $this->belongsTo(Part::class);
    }

    public function service(): BelongsTo
    {
        return $this->belongsTo(Service::class);
    }

    /**
     * Scope a query to only include My items
     *
     * @param \Illuminate\Database\Eloquent\Builder $query
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function scopeMy($query)
    {
        if (!Auth::check()) {
            return $query;
        }

        $user = UserHelper::getUser();

        if ($user->isService()) {
            return $query
                ->where(['service_id' => $user->getCurrentServiceId()]);
        }

        if ($user->isManager()) {
            abort('403');
        }
    }

}