phplaravellaravel-livewirelivewire-3

File Upload Suddenly Stops Working in Laravel 12 with Livewire on Laragon


I am developing an application using Laravel 12 and Livewire, hosted locally on Laragon. Initially, the file upload feature worked perfectly. I was able to upload images successfully, and they were saved correctly in the storage/app/public directory.

However, today, I noticed that the upload functionality has stopped working:

  1. When I try to upload an image, the file is no longer saved to the storage directory, and no error messages are thrown.
  2. I modified the validation rule for the image field from nullable to required to test if the file is being received. Surprisingly, the validation fails with the error The image field is required, even when I have selected an image in the input field.
  3. I double-checked the form and file input, and the correct file is being selected in the browser.
<?php

namespace App\Livewire;

use Livewire\Component;
use Livewire\WithFileUploads;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;

class CreateDonasi extends Component
{
    use WithFileUploads;

    public $image;

    public function submit()
    {
        $this->validate([
            'image' => 'required|image|max:5120',
        ]);

        if ($this->image) {
            $filename = Str::random(30) . '.' . $this->image->getClientOriginalExtension();
            $filePath = $this->image->storeAs('donations', $filename, 'public');
        }
    }

    public function render()
    {
        return view('livewire.create-donasi');
    }
}
<form wire:submit.prevent="submit" class="space-y-6">
     <!-- Upload Gambar -->
        <div>
          <label class="block text-sm font-medium text-gray-700">Gambar (opsional)</label>
          <input wire:model="image" type="file" accept="image/*"
                 class="mt-1 block w-full p-3 rounded-xl border border-gray-300 shadow-sm focus:border-blue-500 focus:ring focus:ring-blue-200 focus:ring-opacity-50" />
          @error('image') <p class="text-red-600 text-sm mt-1">{{ $message }}</p> @enderror
        </div>
      </div>
</form>

Environment details:

Steps I have already tried:

This issue didn’t occur when I tested the functionality yesterday. The image upload worked perfectly then, but now it fails as if no file is being sent in the request.

What could have changed or caused this issue? How can I debug or resolve this behavior?

Any insights or suggestions would be greatly appreciated!


Solution

  • I resolved the error by uncommenting the upload_tmp_dir directive in my php.ini file and setting it to c:\windows\temp. After this change, everything worked as expected. The solution was found here Link