addMediaCollection('defaultSingleFile')->singleFile(); $this->addMediaCollection('conversionsWithDefault') ->singleFile() ->withFallback(fn ($parent) => ['default.jpg', 'public']) ->registerMediaConversions(function () { $this->addMediaConversion('tiny')->width(200)->height(200); }); $this->addMediaCollection('images'); $this->addMediaCollection('singleForced')->singleFile()->forceFileName(function ($model, $name) { return $name.' '.now()->format('Y-m-d'); }); $this->addMediaCollection('multipleForced')->forceFileName(function ($model, $name) { return $name.' '.now()->format('Y-m-d'); }); $this->addMediaCollection('singleStoringHook')->singleFile()->storing(function ($adder, $fileName) { return $adder->withCustomProperties([ 'use' => 'AAA', 'ttt' => pathinfo($fileName, PATHINFO_FILENAME), ]); }); $this->addMediaCollection('singleWithEvent')->singleFile()->stored(function (Media $media) { Event::dispatch(new MediaStored($media)); }) ->destroyed(fn ($model) => Event::dispatch(new MediaDestroyed($model))); $this->addMediaCollection('multipleFilesWithEvent')->stored(function (Media $media) { Event::dispatch(new MediaStored($media)); }); $this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path) => [ 'test' => Str::camel($path), ])->withPropertyValidation(fn ($path) => [ 'test' => 'string|max:10', ]); } }