'bool' ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'firstname', 'lastname', 'subject', 'email', 'message', 'order_number', 'file', ]; /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { // * EVENT CLOSURES. static::creating(function (self $model) { // * Store joined file. if ($model->file) { $model->file = FileStorageHelper::storeFile($model, $model->file, true); } $toMail = GeneralConfig::query()->where('type', GeneralConfigType::global()) ->firstOrFail()->data->contact_us_destination_email->value ?? config('mail.from.address'); // * Envoi du mail d'alerte. Mail::to($toMail)->send(new SendContactMail($model)); }); static::deleted(function (self $model) { if ($model->file) { FileStorageHelper::removeFile($model, 'file'); } }); } // * RELATIONSHIPS /** * BelongsTo order relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function order() { return $this->belongsTo(Order::class, 'order_number', 'reference'); } }