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

hjortur17's avatar

Request return null

Hello, i'm trying to update a image in my dashboard but when I submit the update form it always return with:

Call to a member function store() on null

I have dd and look in the request and it looks like i'm passing in a image. Any ideas how to fix that? This posed is relate to my other post: https://laracasts.com/discuss/channels/laravel/update-a-image-path

But here is my update method in the Controller:

public function update(Request $request, $id)
       {
              $data = $request->except('image_path');
              $data['image_path'] = request()->file('image_path')->store('images', 'public');
              $camping->update($data);

              return redirect('/stjornbord/tjaldsvæði/breyta');
       }
0 likes
5 replies
RonB1985's avatar

What does $request->image_path->store('images', 'public'); do?

request()->file seems to be null

shez1983's avatar

can you show us the dd of request? also why do you use reques() when you have a $request being passed in.. it doesnt matter much but for code consistency use $request->file()... imo null means that image_path is null..

munazzil's avatar

Just try as like below your missing some data where are you getting this camping?

   public function update(Request $request, Camping $camping)
   {
          $data = $request->except('image_path');
          $data['image_path'] = $request()->file('image_path')->store('images', 'public');
          $camping->update($data);

          return redirect('/stjornbord/tjaldsvæði/breyta');
   }
edoc's avatar
edoc
Best Answer
Level 24

Do you have enctype="multipart/form-data" on your form element?

<form action="/your-url" method="post" enctype="multipart/form-data">
</form>

@hjortur17

hjortur17's avatar

Thanks @edoc - There was nothing wrong with to function. But here is the final result:

$camping = Camping::where('id', '=', $id)->first();

              $data = $request->except('image_path');
              $data['image_path'] = request()->file('image_path')->store('images', 'public');
              
              $camping->update($data);

Please or to participate in this conversation.