validate(); $author = Auth::user(); if ($this->file) { $post = Post::create([ 'extension' => $this->file->getClientOriginalExtension(), 'rating' => $this->rating, ]); if ($post) { $author->posts()->save($post); // Save the full image $this->file->storeAs("posts/$post->id", 'full'); $fullImg = Storage::get("posts/$post->id/full"); // Create thumbnail preview $thumb = Image::read($fullImg)->cover(width: 512, height: 512); Storage::put("posts/$post->id/thumb", $thumb->encodeByMediaType()); // Create smaller preview image $preview = Image::read($fullImg)->scaleDown(width: 1280, height: 720); Storage::put("posts/$post->id/preview", $preview->encodeByMediaType()); return $this->redirect("/posts/$post->id"); } } return $this->redirect('/upload'); } }