'required|image|max:65536'])] public $files = []; #[Validate('required|in:safe,suggestive,explicit')] public $rating = 'safe'; #[Title('Upload')] public function render() { return view('livewire.pages.upload'); } public function createPost() { $this->validate(); $author = Auth::user(); foreach ($this->files as $file) { if ($file) { $post = Post::create([ 'extension' => $file->getClientOriginalExtension(), 'rating' => $this->rating, 'hash' => $file->hashName(), ]); if ($post) { $author->posts()->save($post); // Save the full image $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'); } }