first commit
This commit is contained in:
84
app/Models/SupportEcosystemPartner.php
Normal file
84
app/Models/SupportEcosystemPartner.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Backpack\CRUD\app\Models\Traits\CrudTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
|
||||
use Ericli1018\AwesomeFieldsForBackpack\Models\Traits\HasUploadImgFields;
|
||||
|
||||
class SupportEcosystemPartner extends Model
|
||||
{
|
||||
use CrudTrait;
|
||||
use HasFactory;
|
||||
use HasTranslations;
|
||||
use HasUploadImgFields;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| GLOBAL VARIABLES
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
protected $table = 'support_ecosystem_partners';
|
||||
// protected $primaryKey = 'id';
|
||||
// public $timestamps = false;
|
||||
protected $guarded = ['id'];
|
||||
// protected $fillable = [];
|
||||
// protected $hidden = [];
|
||||
public $translatable = ['title', 'description', 'website'];
|
||||
protected $casts = [
|
||||
'photos' => 'array',
|
||||
];
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| FUNCTIONS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::deleting(function($obj) {
|
||||
if (count((array)$obj->photos)) {
|
||||
foreach ($obj->photos as $item) {
|
||||
\Storage::disk('public')->delete($item['file_path']);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| RELATIONS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| SCOPES
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public function supportEcosystemPartnerCatalog()
|
||||
{
|
||||
return $this->belongsTo(SupportEcosystemPartnerCatalog::class, 'support_ecosystem_partner_catalog_id');
|
||||
}
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| ACCESSORS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| MUTATORS
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
public function setPhotosAttribute($value)
|
||||
{
|
||||
$attribute_name = "photos";
|
||||
$disk = "public";
|
||||
$destination_path = "support_ecosystem_partners";
|
||||
|
||||
$this->uploadImgMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user