2020-11-17 13:41:31 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
2021-03-17 09:28:02 +01:00
|
|
|
class Order extends Model
|
2020-11-17 13:41:31 +01:00
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
2021-03-27 20:55:16 +01:00
|
|
|
/**
|
|
|
|
|
* use carefully
|
|
|
|
|
*/
|
2020-11-17 13:41:31 +01:00
|
|
|
public function products() {
|
2021-03-27 20:55:16 +01:00
|
|
|
return $this->belongsToMany(Product::class, 'order_lines', 'order_id', 'product_id');
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-08 15:49:20 +02:00
|
|
|
//Relations
|
2021-03-27 20:55:16 +01:00
|
|
|
public function lines()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(OrderLine::class);
|
2020-11-17 13:41:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function status() {
|
|
|
|
|
return $this->belongsTo('App\Models\OrdersStatus', 'status_id');
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-27 20:55:16 +01:00
|
|
|
public function customer() {
|
2021-03-29 15:10:07 +02:00
|
|
|
return $this->belongsTo(Customers::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function timeslot()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasOne(Timeslot::class);
|
2020-11-17 13:41:31 +01:00
|
|
|
}
|
2021-04-08 15:49:20 +02:00
|
|
|
|
|
|
|
|
//Formattages
|
|
|
|
|
public function getFormattedTotalTtcAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->attributes['formattedTotalTtc'] = sprintf('%s €', number_format($this->attributes['total'], 2, ',', ' '));
|
|
|
|
|
}
|
2020-11-17 13:41:31 +01:00
|
|
|
}
|