Edit File: ProviderUpdate.php
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Spatie\Translatable\HasTranslations; class ProviderUpdate extends BaseModel { use HasFactory, HasTranslations; const IMAGEPATH = 'providers'; public $translatable = ['store_name', 'store_description']; protected $fillable = [ 'name', 'image', 'store_description', 'store_name', 'identity_number', 'tax_number', 'civil_registration_number', 'whatsapp_country_code', 'whatsapp_phone', 'logo', 'preparing_time', 'minimum_order', 'category_id', 'sub_categories', 'city_id', 'neighborhood_id', 'lat', 'lng', 'map_desc', 'bank_name', 'account_number', 'account_name', 'iban', 'bank_account_image', 'delivery_method', ]; public function setLogoAttribute($value): void { if (null != $value && is_file($value)) { isset($this->attributes['logo']) ? $this->deleteFile($this->attributes['logo'], self::IMAGEPATH) : ''; $this->attributes['logo'] = $this->uploadAllTyps($value, self::IMAGEPATH); } } public function getImageAttribute(): string { if ($this->attributes['image']) { $image = $this->getImage($this->attributes['image'], self::IMAGEPATH); } else { $image = ''; } return $image; } public function getLogoAttribute(): string { if ($this->attributes['logo']) { $logo = $this->getImage($this->attributes['logo'], self::IMAGEPATH); } else { $logo = ''; } return $logo; } public function setSubCategoriesAttribute($value) { $this->attributes['sub_categories'] = is_array($value) ? json_encode($value) : null; } public function getSubCategoriesAttribute() { return json_decode($this->attributes['sub_categories'], true); } public function getBankAccountImageAttribute(): ?string { if ($this->attributes['bank_account_image']) { $image = $this->getImage($this->attributes['bank_account_image'], BankAccount::IMAGEPATH); } else { $image = ''; } return $image; } public function setBankAccountImageAttribute($value): void { if (null != $value && is_file($value)) { isset($this->attributes['bank_account_image']) ? $this->deleteFile($this->attributes['bank_account_image'], BankAccount::IMAGEPATH) : ''; $this->attributes['bank_account_image'] = $this->uploadAllTyps($value, BankAccount::IMAGEPATH); } } // Relations public function mainCategory(): BelongsTo { return $this->belongsTo(Category::class, 'category_id'); } public function city(): BelongsTo { return $this->belongsTo(City::class); } public function category(): BelongsTo { return $this->belongsTo(Category::class); } public function provider(): BelongsTo { return $this->belongsTo(Provider::class); } public function neighborhood(): BelongsTo { return $this->belongsTo(Neighborhood::class); } }
Back to File Manager