<?php

namespace App;

use App\Traits\ModelTimeFormat;
use Illuminate\Database\Eloquent\Model;
use App\Traits\ModelLogChanging;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class Supplier extends Model
{
    use ModelLogChanging;
    use ModelTimeFormat;
    use SoftDeletes;
    protected $fillable = ['name','contact_man','phone','invoice_title','bank','bank_account','opening_bank'];

    public function material():BelongsToMany
    {
        return $this->belongsToMany(Material::class,'material_suppliers','supplier_id','material_id');
    }

    public function user():BelongsToMany
    {
        return $this->belongsToMany(User::class,'supplier_user','supplier_id','user_id');
    }

    public function scopeFilter($query,$filters)
    {
        return $filters->apply($query);
    }
}
