'required|string|max:255', 'description' => 'required', 'category' => 'required', 'type'=> 'required', 'content' => 'required|string', 'issueDate' => 'required|date', 'expireDate' => 'required|date', 'topicColor' => 'required', 'uploadFilePathName1' => 'nullable|file|max:10240', // 10MB Max 'uploadFilePathName2' => 'nullable|file|max:10240', // 10MB Max ]; public function mount() { $this->types = Shippingnetnewstype::all()->pluck('newstype', 'id'); $this->categories = Shippingnetservergroup::all()->pluck('groupname', 'groupID'); $this->type = Shippingnetnewstype::first()->id; } // public function updatedContent($value) // { // $this->content = $value; // } public function uploadImage() { $this->validate([ 'imageTmp' => 'image|max:2048', // ขนาดไฟล์สูงสุด 2MB ]); $imagePath = $this->imageTmp->store('livewire-tmp', 'public'); $uploadedImageUrl = asset('storage/' . $imagePath); // สร้าง URL // ส่ง URL กลับไปยัง JavaScript $this->emit('imageUploaded', $uploadedImageUrl); } public function submitForm() { $this->validate(); if ($this->uploadFilePathName1) { $filePath1 = $this->uploadFilePathName1->store('runtime/news', 'public'); } if ($this->uploadFilePathName2) { $filePath2 = $this->uploadFilePathName2->store('runtime/news', 'public'); } Shippingnetnews::create([ 'topic' => $this->topic, 'groupID' => $this->category, 'newstype' => $this->type, 'description' => $this->description, 'content' => $this->content, // Quill Editor HTML content 'issueDate' => $this->issueDate, 'expireDate' => $this->expireDate, 'authorDate' => date("Y-m-d"), 'topiccolor' => $this->topicColor, 'uploadFilePathName1' => $filePath1 ?? '', 'uploadFilePathName2' => $filePath2 ?? '', 'uploadFileName1' => $filePath1 ?? '', 'uploadFileName2' => $filePath2 ?? '', ]); $this->resetForm(); if (auth()->guest()) { return redirect()->route('login'); } $this->emit('showNewsList', 'News successfully created.'); } public function removeFile($fileName) { $this->$fileName = null; } public function resetForm() { $this->reset([ 'topic', 'category', 'type', 'description', 'content', 'issueDate', 'expireDate', 'authorDate', 'topicColor', 'uploadFilePathName1', 'uploadFilePathName2' ]); } public function goBack() { if (auth()->guest()) { return redirect()->route('login'); } $this->emit('showNewsList'); } public function render() { return view('livewire.pages.news.news-create'); } }