first commit

This commit is contained in:
Eric Li
2025-06-13 12:09:50 +08:00
commit b12cd07419
545 changed files with 39389 additions and 0 deletions

86
app/Models/Notice.php Normal file
View File

@ -0,0 +1,86 @@
<?php
namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Ericli1018\AwesomeFieldsForBackpack\Models\Traits\HasUploadImgFields;
use App\Models\Traits\LogsActivity;
class Notice extends Model
{
use CrudTrait;
use LogsActivity;
use HasFactory;
use HasUploadImgFields;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'notices';
// protected $primaryKey = 'id';
// public $timestamps = false;
protected $guarded = ['id'];
// protected $fillable = [];
// protected $hidden = [];
protected $casts = [
'post_at' => 'datetime',
'photos' => 'array',
];
protected $attributes = [
'description' => 'N/A',
];
/*
|--------------------------------------------------------------------------
| 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 noticeCatalog()
{
return $this->belongsTo(NoticeCatalog::class, 'news_catalog_id');
}
/*
|--------------------------------------------------------------------------
| SCOPES
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| ACCESSORS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| MUTATORS
|--------------------------------------------------------------------------
*/
public function setPhotosAttribute($value)
{
$attribute_name = "photos";
$disk = "public";
$destination_path = "notices";
$this->uploadImgMultipleFilesToDisk($value, $attribute_name, $disk, $destination_path);
}
}