php - Call to a member function store() on null Laravel 8
Get the solution ↓↓↓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}");
}
Answer
Solution:
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'
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: composer detected issues in your platform: your composer dependencies require a php version ">= 8.0.2".
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.