$ingredient_list List of ingredient and content warnings. * @property-read array $allergen_list List of allergens. * @property-read \App\Lib\XmlInco\NutritionalValues $nutritional_values Tableau des valeurs nutritionelles. * * @property-read \App\Lib\XmlInco\PortionAmount $portion_amount The portion amount for the product, * could be exact or approximative. * @property-read \App\Enums\XmlInco\PortionType $portion_type The portion type. * @property-read boolean $is_seasonal The product is specific of a season. * @property-read integer $arcadia_brand_id Arcadia brand Id. * * * RELATIONS * @property-read \App\Models\ArcadiaBrand $arcadiaBrand The ArcadiaBrand that owns the XmlInco. */ class XmlInco extends Model { use HasFactory; /** * Indicates if an exception should be thrown instead of silently discarding non-fillable attributes. * * ! Override this to simplify xml parse job * * @var boolean */ protected static $modelsShouldPreventSilentlyDiscardingAttributes = false; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'id', 'name', 'description', 'tips', 'preparation_advices', 'sell_arguments', 'allegations', 'ingredient_list', 'allergen_list', 'nutritional_values', 'portion_amount', 'portion_type', 'is_seasonal', 'arcadia_brand_id', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'ingredient_list' => 'array', 'allergen_list' => 'array', 'is_seasonal' => 'boolean', 'portion_amount' => CastsNbPortion::class, 'portion_type' => PortionType::class, 'allegations' => AllegationCast::class, 'nutritional_values' => NutrionalValuesCast::class, ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { static::creating(function (self $model) { // * Make sure portion type is coherent if (!\is_null($model->portion_amount)) { $model->portion_type = $model->portion_amount->getType(); } else { $model->portion_type = null; } }); static::updating(function (self $model) { // * Make sure portion type is coherent if (!\is_null($model->portion_amount)) { $model->portion_type = $model->portion_amount->getType(); } else { $model->portion_type = null; } }); } // * RELATIONS /** * Get the ArcadiaBrand that owns the XmlInco * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function arcadiaBrand(): BelongsTo { return $this->belongsTo(ArcadiaBrand::class); } }