B
B
Banyanchik2020-02-12 00:49:10
Laravel
Banyanchik, 2020-02-12 00:49:10

How to upload image to server in laravel?

Hello everyone, I’m making blog articles, I need to upload a preview image for the article, there is a separate column in the post table where the image name is stored, everything is simple, but I can’t upload the image itself to the server, please tell me what the problem is.
Form:
the form itself is large, because is a form for editing an article

<form action="{{ route('posts.update',$item->id) }}" method="POST" enctype=«multipart/form-data»>
.....
<div class="custom-file">
 <input type="file" class="custom-file-input" id="customFile" name="prevyu">
  <label class="custom-file-label" for="customFile" placeholder="Select file"></label>
                            </div>
......
</form>

In controller:
$prevyu = $request->file('prevyu')->store('public/img');

When trying to upload an image, it gives an error:
Call to a member function store() on null
Here is the dump:
5e4322e411b9f209925552.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Banyanchik, 2020-02-12
@Banyanchik

The problem was the quotes in the form: method="POST" enctype="multipart/form-data"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question