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

76 lines
1.6 KiB
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
/**
2022-09-03 16:56:16 +02:00
* BelongsToMany products relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
2021-03-27 20:55:16 +01:00
*/
2022-08-25 12:26:43 +02:00
public function products()
{
2021-03-27 20:55:16 +01:00
return $this->belongsToMany(Product::class, 'order_lines', 'order_id', 'product_id');
}
2022-09-03 16:56:16 +02:00
/**
* hasMany lines relation
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
2021-03-27 20:55:16 +01:00
public function lines()
{
return $this->hasMany(OrderLine::class);
2020-11-17 13:41:31 +01:00
}
2022-09-03 16:56:16 +02:00
/**
* BelongsTo order_status relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2022-08-25 12:26:43 +02:00
public function status()
{
2020-11-17 13:41:31 +01:00
return $this->belongsTo('App\Models\OrdersStatus', 'status_id');
}
2022-09-03 16:56:16 +02:00
/**
* BelongsTo customer relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2022-08-25 12:26:43 +02:00
public function customer()
{
2021-03-29 15:10:07 +02:00
return $this->belongsTo(Customers::class);
}
2022-09-03 16:56:16 +02:00
/**
* hasOne timeslot relation
*
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
2021-03-29 15:10:07 +02:00
public function timeslot()
{
return $this->hasOne(Timeslot::class);
2020-11-17 13:41:31 +01:00
}
2022-09-03 16:56:16 +02:00
/**
* Custom Attribute
*
* @return string
*/
public function getFormattedTotalTtcAttribute()
{
2022-09-03 16:56:16 +02:00
$this->attributes['formattedTotalTtc'] = sprintf(
'%s €',
number_format($this->attributes['total'], 2, ',', ' ')
);
return $this->attributes['formattedTotalTtc'];
}
2020-11-17 13:41:31 +01:00
}