Files
opensem/app/Models/Shop/Invoice.php
2024-02-22 21:28:33 +01:00

65 lines
1.6 KiB
PHP

<?php
namespace App\Models\Shop;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use LaracraftTech\LaravelDateScopes\DateScopes;
use Venturecraft\Revisionable\RevisionableTrait;
use Znck\Eloquent\Traits\BelongsToThrough;
class Invoice extends Model
{
use BelongsToThrough, DateScopes, RevisionableTrait, SoftDeletes;
protected $guarded = ['id'];
protected $table = 'shop_invoices';
protected $revisionCreationsEnabled = false;
protected $dontKeepRevisionOf = ['updated_by', 'updated_at'];
public function payments(): HasMany
{
return $this->hasMany(InvoicePayment::class);
}
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class, 'customer_id');
}
public function address(): BelongsTo
{
return $this->belongsTo(CustomerAddress::class, 'invoice_address_id');
}
public function scopeByCustomer($query, $customerId)
{
return $query->where('customer_id', $customerId);
}
public function scopeByUUID($query, $uuid)
{
return $query->where('uuid', $uuid);
}
public function scopeById($query, $id)
{
return $query->where('id', $id);
}
public function scopeByPeriod($query, $start, $end, $field = 'created_at')
{
return $query->whereBetween($field, [$start, $end]);
}
}