Which version of Laravel do you use?
https://laravel.com/docs/7.x/requests#files
Or you can use Storage
Here i have put my controller method. I did not understand why this error comes when I upload an image. Problem is data is stored but I don't understand what is the cause for this error?
public function store(PostRequest $request, Post $post)
{
// dd($request->all());
$input = $request->validated();
if($file = $request->file('photo_id')){
$name = time() . $file->getClientOriginalName();
$file->move('images', $name);
$photo = Photo::create(['file'=>$name]);
$input['photo_id'] = $photo->id;
}
$post = auth()->user()->posts()->create($input);
// dd($post);
$post->tags()->attach(request('tags'));
return redirect(route('posts.index'))->with('message','Posts created succesfully');
}
Change it like this, then of course you have to change your controller as well.
<div class="form-group">
<label for="path">PostImage</label>
<input id="path" class="form-control-file {{ $errors->first('path', 'is-invalid') }}" type="file" name="path" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">
Please upload a valid image file. Size of image should not be more than 2MB.
</small>
@error('path')
<small class="form-text text-red">{{ $message }}</small>
@enderror
</div>
Please or to participate in this conversation.