91 lines
2.3 KiB
PHP
91 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Products extends Model
|
|
{
|
|
|
|
protected $casts = [
|
|
'star' => 'boolean'
|
|
];
|
|
|
|
protected static function booted()
|
|
{
|
|
static::creating(function ($product) {
|
|
if (!$product->incoNutritionalValues) {
|
|
$inc = new IncoNutritionalValues();
|
|
$inc->product()->associate($inc);
|
|
}
|
|
$product->preparation_advice = clean($product->preparation_advice);
|
|
$product->ingredients = clean($product->ingredients);
|
|
$product->tips = clean($product->tips);
|
|
});
|
|
static::updating(function ($product) {
|
|
$product->preparation_advice = clean($product->preparation_advice);
|
|
$product->ingredients = clean($product->ingredients);
|
|
$product->tips = clean($product->tips);
|
|
});
|
|
}
|
|
|
|
public function pictograms()
|
|
{
|
|
return $this->belongsToMany(
|
|
ProductPictograms::class,
|
|
"products_pictograms",
|
|
"product_id",
|
|
"pictogram_id"
|
|
);
|
|
}
|
|
|
|
public function range()
|
|
{
|
|
return $this->belongsTo(Ranges::class);
|
|
}
|
|
|
|
public function meatType()
|
|
{
|
|
return $this->belongsTo(MeatTypes::class, 'meat_type_id');
|
|
}
|
|
|
|
public function consumptionTimes()
|
|
{
|
|
return $this->belongsTo(ConsumptionTimes::class, 'consumption_times_id');
|
|
}
|
|
|
|
public function recipe()
|
|
{
|
|
return $this->belongsTo(Recipes::class);
|
|
}
|
|
|
|
public function incoNutritionalValues()
|
|
{
|
|
return $this->hasOne(IncoNutritionalValues::class, 'product_id');
|
|
}
|
|
|
|
public function balancedMenu()
|
|
{
|
|
return $this->hasOne(BalancedMenus::class, 'product_id');
|
|
}
|
|
|
|
public function recipes()
|
|
{
|
|
return $this->belongsToMany(Recipes::class, 'recipes_products', 'product_id', 'recipe_id');
|
|
}
|
|
|
|
public function customers()
|
|
{
|
|
return $this->belongsToMany(Customers::class, 'cart', 'product_id', 'customer_id');
|
|
}
|
|
|
|
public function reductions()
|
|
{
|
|
return $this->belongsToMany(Reductions::class, 'reduction_config', 'product_id', 'reduction_id');
|
|
}
|
|
|
|
public function xmlInco()
|
|
{
|
|
return $this->belongsTo(XmlInco::class, 'xml_inco_id');
|
|
}
|
|
}
|