46 lines
974 B
PHP
46 lines
974 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Order extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* use carefully
|
|
*/
|
|
public function products()
|
|
{
|
|
return $this->belongsToMany(Product::class, 'order_lines', 'order_id', 'product_id');
|
|
}
|
|
|
|
// Relations
|
|
public function lines()
|
|
{
|
|
return $this->hasMany(OrderLine::class);
|
|
}
|
|
|
|
public function status()
|
|
{
|
|
return $this->belongsTo('App\Models\OrdersStatus', 'status_id');
|
|
}
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(Customers::class);
|
|
}
|
|
|
|
public function timeslot()
|
|
{
|
|
return $this->hasOne(Timeslot::class);
|
|
}
|
|
|
|
// Formattages
|
|
public function getFormattedTotalTtcAttribute()
|
|
{
|
|
return $this->attributes['formattedTotalTtc'] = sprintf('%s €', number_format($this->attributes['total'], 2, ',', ' '));
|
|
}
|
|
}
|