When I click on save to update the data on my edit page, I get the following error.
call to a member function store() on null
public function update(User $user) { $this->authorize('update', $user->profile); $data = request()->validate([ 'title' => 'required', 'description' => 'required', 'url' => 'url', 'image' => '', ]); $imagePath = request('image') ->store('profile', 'public'); $image = Image::make(public_path("storage/{$imagePath}")) ->fit(1000, 1000); $image->save(); dd($data); auth()->user->profile->update(array_merge( ['image' => $imagePath] )); return redirect("/profile/{$user->id}"); }
Advertisement
Answer
As a result of $request->file(‘file’) is returning null, and you are trying to call a method on null, resulting in the exception.
Due to the way Laravel handles PUT and PATCH requests, you will need to send your request in a POST request, and supply _method with the value PUT in the header. This is what Laravel expects.
'image' => 'required'