FileCategory::class, 'type' => FileType::class ]; /** * Crud label column * * @var string */ protected $crudLabelColumn = 'name'; /** * Crud value column * * @var string */ protected $crudValueColumn = 'id'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = ['type', 'uri', 'file', 'name', 'category']; /** * File * * @param array $attributes */ public function __construct(array $attributes = []) { self::$editableProperties = [ 'name' => [ 'label' => trans('Nom'), 'type' => CrudType::string(), 'nullable' => false, 'actions' => [ CrudAction::viewAny(), CrudAction::view(), CrudAction::update(), CrudAction::create() ] ], 'type' => [ 'label' => trans('Type'), 'type' => CrudType::enum(), 'enum' => FileType::class, 'required' => true, 'nullable' => false, 'actions' => [ CrudAction::viewAny(), CrudAction::view(), CrudAction::create() ] ], 'category' => [ 'label' => trans('Categorie'), 'type' => CrudType::enum(), 'enum' => FileCategory::class, 'required' => true, 'nullable' => false, 'actions' => [ CrudAction::viewAny(), CrudAction::view(), CrudAction::update(), CrudAction::create() ] ], 'uri' => [ 'label' => trans('Lien uri'), 'type' => CrudType::uri(), 'required' => false, 'nullable' => true, 'validate' => [ 'required_without:file', 'nullable' ], 'actions' => [ CrudAction::view(), CrudAction::create() ] ], 'file' => [ 'label' => trans('Fichier'), 'type' => CrudType::file(), 'required' => false, 'nullable' => true, 'validate' => [ 'required_without:uri', 'nullable', 'max:5120', //phpcs:ignore Generic.Files.LineLength.TooLong 'mimetypes:application/pdf,text/csv,text/plain,application/csv,text/comma-separated-values,text/anytext,application/octet-stream,application/txt', // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed function ($attribute, $value, $fail) { if (!in_array($value->getClientMimeType(), ['application/vnd.ms-excel', 'application/pdf'])) { //phpcs:ignore Generic.Files.LineLength.TooLong $fail(__('Le fichier doit être d\'un mime type application/vnd.ms-excel ou application/pdf')); } } ], 'accept' => 'application/pdf,text/csv', 'actions' => [ CrudAction::view(), CrudAction::create() ] ], 'created_at' => [ 'label' => trans('Créé le'), 'type' => CrudType::string(), 'actions' => [ CrudAction::viewAny(), CrudAction::view() ] ] ]; parent::__construct($attributes); } /** * Perform any actions required after the model boots. * * @return void */ protected static function booted() { static::created(function (File $file) { event(new FileCreated($file, \auth()->user())); }); } // * RELATIONSHIPS /** * MorphTo parent object relation * * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ public function parent() { return $this->morphTo(); } /** * MorphTo parent object site relation * * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ public function parentSite() { return $this->morphTo('parent', 'site'); } /** * MorphTo parent object project relation * * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ public function parentProject() { return $this->morphTo('parent', 'project'); } }