You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.6 KiB
97 lines
2.6 KiB
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Traits\Validatable;
|
|
use App\Models\Traits\ValidationMaker;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Collection extends Model
|
|
{
|
|
use HasFactory, SoftDeletes, Validatable, ValidationMaker;
|
|
|
|
protected $fillable = [
|
|
"name",
|
|
"path",
|
|
"public",
|
|
"disk",
|
|
"count",
|
|
"tmp_support",
|
|
"remove_tmp_time",
|
|
"max_file_size",
|
|
"min_file_size",
|
|
"max_width",
|
|
"min_width",
|
|
"max_height",
|
|
"min_height",
|
|
"alt_required",
|
|
"description_required",
|
|
"exts",
|
|
"ext",
|
|
"mimetypes",
|
|
"model",
|
|
"expire_date",
|
|
];
|
|
|
|
protected $casts = [
|
|
'exts' => 'array',
|
|
'mimetypes' => 'array',
|
|
];
|
|
|
|
public function files()
|
|
{
|
|
return $this->hasMany(File::class);
|
|
}
|
|
|
|
protected function exts(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
set: fn ($value) => json_encode($value),
|
|
);
|
|
}
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['max:100', 'Required', 'string', 'unique:collections,name'],
|
|
"path" => ['max:255', 'nullable', 'string'],
|
|
"public" => ['nullable', 'boolean'],
|
|
"disk" => ['required', 'string', 'max:255'],
|
|
"count" => ['required', 'numeric', 'max:255'],
|
|
"tmp_support" => ['required', 'boolean'],
|
|
"remove_tmp_time" => ['date_format:Y-m-d H:i:s', 'nullable'],
|
|
"max_file_size" => ['nullable', 'numeric'],
|
|
"min_file_size" => ['nullable', 'numeric'],
|
|
"max_width" => ['nullable', 'numeric'],
|
|
"min_width" => ['nullable', 'numeric'],
|
|
"max_height" => ['nullable', 'numeric'],
|
|
"min_height" => ['nullable', 'numeric'],
|
|
"alt_required" => ['required', 'boolean'],
|
|
"description_required"=> ['required','boolean'],
|
|
"exts" => ['nullable'],
|
|
"ext" => ['string','max:100','nullable'],
|
|
"mimetypes"=> ['nullable'],
|
|
"expire_date" => ['date_format:Y-m-d H:i:s','nullable'],
|
|
];
|
|
}
|
|
|
|
protected function mimetypes(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
set: fn ($value) => json_encode($value),
|
|
);
|
|
}
|
|
|
|
public function getExts()
|
|
{
|
|
return implode(",", app()->collection->exts);
|
|
}
|
|
|
|
public function getMimeTypes()
|
|
{
|
|
return implode(",", app()->collection->mimetypes);
|
|
}
|
|
}
|