The error message "The image failed to upload" suggests that the Livewire validation rules are not being met. One possible solution is to update the validation rules in the CreatePost component to match the rules defined in the config/livewire file. Here's an example:
protected $rules = [
'image' => 'nullable|mimes:png,jpg,jpeg|max:140000',
'gif' => 'nullable|mimes:gif|max:140000',
'video' => 'nullable|mimes:mp4|max:140000',
'title' => 'required|min:4|max:85',
'category' => 'required|integer|exists:categories,id',
'description' => 'required|min:4',
'name' => 'nullable',
];
Then, update the createPost method to use the $rules property instead of defining the rules inline:
public function createPost()
{
if (auth()->check()) {
$this->validate();
$clientIP = request()->ip();
$post = Post::create([
'user_id' => auth()->id(),
'category_id' => $this->category,
'status_id' => 1,
'title' => $this->title,
'description' => $this->description,
'image' => $this->image ? $this->image->store('images') : null,
'video' => $this->video ? $this->video->store('videos') : null,
'gif' => $this->gif ? $this->gif->store('gifs') : null,
'user_ip' => $clientIP,
]);
$post->save();
}
}
This should ensure that the Livewire validation rules are being applied correctly.