Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raducu.mirescu's avatar

Laravel 5.6 request->file returns null and cannot store files

I'm trying to upload files from my app but for some reasons I get " Call to a member function store() on null ". I have created the storage:link.

This is my view:


<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <form action="/upload" method="post">
        @csrf                
                <input type="file" name="xml">
                <input type="Submit" class="btn btn-primary" value="Send">
            </form>
        </div>
    </div>
</div>

And my controller:

public function upload(Request $req)
{   

    $path = $req->file('xml')->store('xml');

    return $path;
}

Is there something I'm missing or doing wrong?

Thank you!

0 likes
3 replies
rin4ik's avatar
rin4ik
Best Answer
Level 50

include enctype="multipart/form-data" to your form

<form action="/upload" method="post" enctype="multipart/form-data">
3 likes
albusSeverus's avatar

Solved my problem as well for file upload on edit form.

Thanks.

Please or to participate in this conversation.