| Current Path : /home/users/unlimited/www/sigmaerp.codeskitter.site/app/Models/ |
| Current File : /home/users/unlimited/www/sigmaerp.codeskitter.site/app/Models/Service.php |
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use App\Models\OrderedProducts;
use App\Models\Tax;
use App\Models\User;
class Service extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'description',
'unit_price',
'tax_id',
'tax_type',
'image_path',
'status',
];
/**
* Insert & update User Id's
* */
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->created_by = auth()->id();
$model->updated_by = auth()->id();
});
static::updating(function ($model) {
$model->updated_by = auth()->id();
});
}
/**
* Get the tax associated with the service.
*
* @return BelongsTo
*/
public function tax(): BelongsTo
{
return $this->belongsTo(Tax::class);
}
/**
* Relationship with Order
*
* @return BelongsTo
*/
public function orderedProducts() : BelongsTo
{
return $this->belongsTo(OrderedProducts::class, 'service_id');
}
/**
* Define the relationship between Order and User.
*
* @return BelongsTo
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
}