'required', 'pre_tag_xml' => 'required', 'tag_xml' => 'required', 'type_field'=> 'required', 'format_field' => 'required|string', 'name' => 'required', 'thai_name' => 'required', 'description' => 'required', 'uploadFilePathName1' => 'nullable|file|max:10240', ]; public function mount() { } public function uploadImage() { $this->validate([ 'img' => 'image|max:2048', ]); if (!Storage::disk('public')->exists('images/error-tran')) { Storage::disk('public')->makeDirectory('images/error-tran', 0755, true); } $imagePath = $this->imageTmp->store('images/error-tran', 'public'); $uploadedImageUrl = asset('storage/' . $imagePath); $this->emit('imageUploaded', $uploadedImageUrl); } public function submitForm() { $this->validate(); // if (!Storage::disk('public')->exists('runtime/error-tran')) { // Storage::disk('public')->makeDirectory('runtime/error-tran', 0755, true); // } if ($this->uploadFilePathName1) { $originalName = $this->uploadFilePathName1->getClientOriginalName(); // ดึงชื่อไฟล์เดิม $filePath1 = $this->uploadFilePathName1->storeAs('images/error-tran', $originalName, 'public'); // เก็บด้วยชื่อเดิม if (!$filePath1) { session()->flash('error', 'File upload failed.'); return; } } MasterMapfieldXml::create([ 'xml_type' => $this->xml_type, 'pre_tag_xml' => $this->pre_tag_xml, 'tag_xml' => $this->tag_xml, 'type_field' => $this->type_field, 'format_field' => $this->format_field, 'name' => $this->name, 'thai_name' => $this->thai_name, 'description' => $this->description, 'img' => $filePath1 ?? '', ]); $this->resetForm(); return auth()->guest() ? redirect()->route('login') : $this->emit('showList', 'Successfully created.'); } public function removeFile($fileName) { $this->$fileName = null; } public function resetForm() { $this->reset([ 'xml_type', 'pre_tag_xml', 'tag_xml', 'type_field', 'format_field', 'name', 'thai_name', 'description', 'uploadFilePathName1' ]); } public function goBack() { if (auth()->guest()) { return redirect()->route('login'); } $this->emit('showList'); } public function render() { return view('livewire.pages.master-file-xml.master-file-create'); } }