44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
|
||
|
class Product extends Model
|
||
|
{
|
||
|
use HasFactory, SoftDeletes;
|
||
|
|
||
|
public function category()
|
||
|
{
|
||
|
return $this->belongsTo(ProductCategory::class,'product_category_id','id')->withTrashed();
|
||
|
}
|
||
|
|
||
|
public function subcategory()
|
||
|
{
|
||
|
return $this->belongsTo(ProductSubcategory::class,'product_subcategory_id','id')->withTrashed();
|
||
|
}
|
||
|
|
||
|
public function brand()
|
||
|
{
|
||
|
return $this->belongsTo(Brand::class,'brand_id','id')->withTrashed();
|
||
|
}
|
||
|
|
||
|
public function model()
|
||
|
{
|
||
|
return $this->belongsTo(ProductModel::class,'product_model_id','id')->withTrashed();
|
||
|
}
|
||
|
|
||
|
public function loans()
|
||
|
{
|
||
|
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','=',LoanType::where('name','=','Loan')->first()->id);
|
||
|
}
|
||
|
|
||
|
public function reservations()
|
||
|
{
|
||
|
return $this->morphtoMany(User::class, 'loanable','loans')->where('loan_type_id','!=',LoanType::where('name','=','Loan')->first()->id);
|
||
|
}
|
||
|
|
||
|
}
|