Skip to main content
  1. About
  2. For Teams
Asked
Viewed 2k times
Part of PHP Collective
0

I create a component to create a post, my form has an input file with wire:model="post.post_image" , when I choose an image, I create a function to print the image data but it still gives me null.

use WithFileUploads;
public $post;

protected $rules = [
    'post.post_image' => 'sometimes|image|max:5000',
    ];

public function mount ()
{
    $this->post = new Post;
}
public function uploadPostImage(Request $request)
{
    dd($request->file('post.post_image'));
}
public function render ()
{
    return view('livewire.post.create');
}

html code :

<div class="sm:col-span-6"> <input type="file" accept="image/*" wire:model="post.post_image" name="post.post_image" wire:change="uploadPostImage"> </div>

when i upload image it give me null and in console give me this error

error

1 Answer 1

0

As you see here in the model of implementation for file upload, it is useless to count on the Request while using Livewire. Check the model of implementation in the documentation, it is pretty easy.

Sign up to request clarification or add additional context in comments.

2 Comments

I check the documentation so many time , but it still give me erro!
Your implementation you posted here, has nothing to do with the documentation on how to upload a file. Please check it again.

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.