ldc-boutique-cnc/app/Models/Order.php

44 lines
960 B
PHP
Raw Permalink Normal View History

2020-11-17 13:41:31 +01:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
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');
}
//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
}
//Formattages
public function getFormattedTotalTtcAttribute()
{
return $this->attributes['formattedTotalTtc'] = sprintf('%s €', number_format($this->attributes['total'], 2, ',', ' '));
}
2020-11-17 13:41:31 +01:00
}