97 lines
2.8 KiB
PHP
97 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Ericli1018\AwesomeFieldsForBackpack\Models\Traits\HasUploadImgFields;
|
|
use Backpack\CRUD\app\Models\Traits\CrudTrait;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class DemoCatalogs extends Model
|
|
{
|
|
use CrudTrait;
|
|
use HasFactory;
|
|
use HasUploadImgFields;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| GLOBAL VARIABLES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
protected $table = 'demo_catalogs';
|
|
// protected $primaryKey = 'id';
|
|
// public $timestamps = false;
|
|
protected $guarded = ['id'];
|
|
// protected $fillable = [];
|
|
// protected $hidden = [];
|
|
protected $casts = [
|
|
'photos' => 'array',
|
|
'text3' => 'array',
|
|
'text4' => 'datetime',
|
|
'text5' => 'datetime',
|
|
'text6' => 'datetime',
|
|
'text7' => 'datetime'
|
|
];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| 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
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public function NewsCatalog() : BelongsTo
|
|
{
|
|
return $this->belongsTo('App\Models\NewsCatalog', 'int1', 'id');
|
|
}
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| SCOPES
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| ACCESSORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| MUTATORS
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
public function setPhotosAttribute($value)
|
|
{
|
|
$attribute_name = "photos";
|
|
$disk = "public";
|
|
$destination_path = "demo_catalogs";
|
|
|
|
$this->uploadImgMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
|
|
}
|
|
|
|
/**
|
|
* for datetime picker
|
|
*/
|
|
public function setDatetimeAttribute($value) {
|
|
$this->attributes['datetime'] = \Carbon\Carbon::parse($value);
|
|
}
|
|
}
|