mastercut/app/Models/Inventory.php

48 lines
1.1 KiB
PHP
Executable File

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Auth;
class Inventory extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'inventory';
protected $fillable = [
'user_id',
'barbershop_id',
'name',
'quantity',
'price',
'description',
];
public function scopeBarbershop(Builder $query): Builder
{
return $query->where('barbershop_id', Auth::user()->barbershop_id);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function barbershop(): BelongsTo
{
return $this->belongsTo(Barbershop::class);
}
public function attachment(): MorphOne
{
return $this->morphOne(Attachment::class, 'attachmentable');
}
}