'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); } static::sendEmailContact($model); }); static::deleted(function (self $model) { if ($model->file) { FileStorageHelper::removeFile($model, 'file'); } }); } /** * Send the email contact. * * @param \App\Models\Contact $model * @return void */ public function sendEmailContact(Contact $model) { $toMail = GeneralConfig::query() ->where('type', GeneralConfigType::global()) ->firstOrFail() ->data->contact_us_destination_email->value ?? config('mail.from.address'); Mail::to($toMail)->send(new SendContactMail($model)); } // * RELATIONSHIPS /** * BelongsTo order relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function order() { return $this->belongsTo(Order::class, 'order_number', 'reference'); } }