<?php

namespace Modules\Inventory\Models\Traits;

use Illuminate\Database\Eloquent\Builder;
use Modules\Inventory\Models\Supplier;

trait HasSupplier
{
    public function supplier()
    {
        return $this->belongsTo(Supplier::class);
    }

    public function scopeSupplier(Builder $query, ?int $supplierId): Builder
    {
        return $query->when($supplierId,
            fn ($q) => $q->where(
                'supplier_id',
                $supplierId
            )
        );
    }
}


