It seems like you've configured the temporary_file_upload correctly in your config/livewire.php. However, to enforce the validation rules and handle the error messages, you need to make sure that you're using the validation within your Livewire component's file upload method.
Here's an example of how you might handle file uploads and validation in your Livewire component:
use Livewire\Component;
use Livewire\WithFileUploads;
class ImageUploader extends Component
{
use WithFileUploads;
public $photo;
public function updatedPhoto()
{
$this->validate([
'photo' => $this->temporary_file_upload['rules'], // Use the rules from the config
]);
}
public function save()
{
// Save logic goes here
}
public function render()
{
return view('livewire.image-uploader');
}
}
In your Blade template, you should also make sure to display the error messages for the user to see. Here's an example of how you might do that:
<div>
<input type="file" wire:model="photo">
@error('photo') <span class="error">{{ $message }}</span> @enderror
<button wire:click="save">Save Photo</button>
</div>
When you use wire:model with a file input, Livewire will automatically upload the file to the temporary directory and run validation rules against it. If the validation fails, Livewire will populate the $errors variable with the appropriate messages, which you can then display in your Blade template using the @error directive.
Make sure that you're using the updated{PropertyName} method to validate the file right after it's been updated. This method is automatically called by Livewire when the specified property changes.
If you follow this pattern, you should be able to enforce the validation rules and provide feedback to the user when a file does not meet the specified criteria.