-
composer.json
Open in GitHub{ // "require": { "php": "^7.4|^8.0", // "spatie/laravel-medialibrary": "^9.4" }, // }
-
app/Models/Recipes/Recipe.php
Open in GitHubuse Spatie\MediaLibrary\HasMedia; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\InteractsWithMedia; class Recipe extends Model implements HasMedia { use InteractsWithMedia; // public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumbnail') ->width(200) ->height(200) ->sharpen(10); $this->addMediaConversion('webp') ->format(Manipulations::FORMAT_WEBP); } // }
-
app/Http/Controllers/Recipes/RecipePhotoController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Models\Recipes\Recipe; use App\Http\Requests\Recipes\RecipePhoto\Store; use Spatie\MediaLibrary\MediaCollections\FileAdder; use Spatie\MediaLibrary\MediaCollections\Models\Media; class RecipePhotoController extends Controller { public function store(Store $request, Recipe $recipe) { $this->authorize('update', $recipe); $recipe->addAllMediaFromRequest()->each(function (FileAdder $fileAdder) { $fileAdder->toMediaCollection('recipe_photos'); }); } // }