File: D:/HostingSpaces/SBogers10/netwerkbrabant.komma.pro/app/KommaApp/Orders/Models/OrderProduct.php
<?php
namespace App\KommaApp\Orders\Models;
use App\KommaApp\Events\Models\Event;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class OrderProduct extends Model
{
protected $table = 'order_products';
use SoftDeletes;
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
protected $guarded = ['id', 'order_id'];
/**
* Get the order belonging to this order
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function order() : BelongsTo
{
return $this->belongsTo(Order::class);
}
// /**
// * Get the belonging event to the product
// *
// * @return BelongsTo
// */
// public function event(): BelongsTo
// {
// return $this->belongsTo(Event::class, 'event_id');
// }
/**
* Get the belonging product
*/
public function productable(): MorphTo
{
return $this->morphTo();
}
/**
* Get the formatted price for with or without vat
*
* @param bool $vat
* @param string $decPoint
* @param string $thousandsSept
* @param int $decimals
* @return string
*/
public function getFormattedPrice($vat = true, $decPoint = '.', $thousandsSept = '', $decimals = 2){
if($vat) return number_format($this->price_including_vat / 100, $decimals, $decPoint, $thousandsSept);
return number_format($this->price / 100, $decimals, $decPoint, $thousandsSept);
}
}