75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Order extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* BelongsToMany products relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
*/
|
|
public function products()
|
|
{
|
|
return $this->belongsToMany(Product::class, 'order_lines', 'order_id', 'product_id');
|
|
}
|
|
|
|
/**
|
|
* hasMany lines relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function lines()
|
|
{
|
|
return $this->hasMany(OrderLine::class);
|
|
}
|
|
|
|
/**
|
|
* BelongsTo order_status relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function status()
|
|
{
|
|
return $this->belongsTo('App\Models\OrdersStatus', 'status_id');
|
|
}
|
|
|
|
/**
|
|
* BelongsTo customer relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customers::class);
|
|
}
|
|
|
|
/**
|
|
* hasOne timeslot relation
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
|
*/
|
|
public function timeslot()
|
|
{
|
|
return $this->hasOne(Timeslot::class);
|
|
}
|
|
|
|
/**
|
|
* Custom Attribute
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getFormattedTotalTtcAttribute()
|
|
{
|
|
$this->attributes['formattedTotalTtc'] = sprintf(
|
|
'%s €',
|
|
number_format($this->attributes['total'], 2, ',', ' ')
|
|
);
|
|
return $this->attributes['formattedTotalTtc'];
|
|
}
|
|
}
|