2020-10-06 17:34:41 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
|
|
class Products extends Model
|
|
|
|
|
{
|
2021-03-20 14:38:15 +01:00
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
protected $casts = [
|
|
|
|
|
'star' => 'boolean'
|
|
|
|
|
];
|
|
|
|
|
|
2021-03-29 14:44:59 +02:00
|
|
|
protected static function booted()
|
|
|
|
|
{
|
|
|
|
|
static::creating(function ($product) {
|
|
|
|
|
if (!$product->incoNutritionalValues) {
|
|
|
|
|
$inc = new IncoNutritionalValues();
|
2021-03-29 15:39:04 +02:00
|
|
|
$inc->product()->associate($inc);
|
2021-03-29 14:44:59 +02:00
|
|
|
}
|
2021-05-05 15:13:33 +02:00
|
|
|
$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);
|
2021-03-29 14:44:59 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
public function pictograms()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsToMany(
|
|
|
|
|
ProductPictograms::class,
|
|
|
|
|
"products_pictograms",
|
2021-04-16 10:21:56 +02:00
|
|
|
"product_id",
|
|
|
|
|
"pictogram_id"
|
2021-02-02 10:26:36 +01:00
|
|
|
);
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
public function range()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Ranges::class);
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-20 14:38:15 +01:00
|
|
|
public function meatType()
|
2021-02-02 10:26:36 +01:00
|
|
|
{
|
2021-02-04 19:06:12 +01:00
|
|
|
return $this->belongsTo(MeatTypes::class, 'meat_type_id');
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-20 14:38:15 +01:00
|
|
|
public function consumptionTimes()
|
2021-02-02 10:26:36 +01:00
|
|
|
{
|
2021-02-04 19:06:12 +01:00
|
|
|
return $this->belongsTo(ConsumptionTimes::class, 'consumption_times_id');
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
public function recipe()
|
|
|
|
|
{
|
2021-02-04 19:06:12 +01:00
|
|
|
return $this->belongsTo(Recipes::class);
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-20 14:38:15 +01:00
|
|
|
public function incoNutritionalValues()
|
2021-02-02 10:26:36 +01:00
|
|
|
{
|
2021-04-16 10:21:56 +02:00
|
|
|
return $this->hasOne(IncoNutritionalValues::class, 'product_id');
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|
2020-10-07 10:28:10 +02:00
|
|
|
|
2021-03-20 14:38:15 +01:00
|
|
|
public function balancedMenu()
|
2021-02-02 10:26:36 +01:00
|
|
|
{
|
2021-02-19 15:24:28 +01:00
|
|
|
return $this->hasOne(BalancedMenus::class, 'product_id');
|
2020-10-07 10:28:10 +02:00
|
|
|
}
|
2020-10-07 16:46:58 +02:00
|
|
|
|
2021-02-04 19:06:12 +01:00
|
|
|
public function recipes()
|
|
|
|
|
{
|
2021-05-04 15:51:14 +02:00
|
|
|
return $this->belongsToMany(Recipes::class, 'recipes_products', 'product_id', 'recipe_id');
|
2021-02-04 19:06:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
public function customers()
|
|
|
|
|
{
|
2021-02-24 09:12:02 +01:00
|
|
|
return $this->belongsToMany(Customers::class, 'cart', 'product_id', 'customer_id');
|
2020-12-10 12:13:33 +01:00
|
|
|
}
|
2020-12-17 17:15:06 +01:00
|
|
|
|
2021-02-02 10:26:36 +01:00
|
|
|
public function reductions()
|
|
|
|
|
{
|
2021-02-19 12:21:56 +01:00
|
|
|
return $this->belongsToMany(Reductions::class, 'reduction_config', 'product_id', 'reduction_id');
|
2020-12-17 17:15:06 +01:00
|
|
|
}
|
2021-04-16 10:21:56 +02:00
|
|
|
|
|
|
|
|
public function xmlInco()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(XmlInco::class, 'xml_inco_id');
|
|
|
|
|
}
|
2020-10-06 17:34:41 +02:00
|
|
|
}
|