T
T
Tarasovych2017-04-18 22:38:26
Laravel
Tarasovych, 2017-04-18 22:38:26

How to resolve "Call to a member function on null" error?

Controller method:

public function update(Request $request, $id)
    {
        $this->validate($request, [
            ...
        ]);

        Blog::find($id)->update($request->all());

        return redirect()->route('blog.index')
            ->with('success','Blog updated successfully');
    }

Error: I don't even know what to wardump here. loops...
Call to a member function update() on null
var_dump($request)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Baranov, 2017-04-18
@Tarasovych

Blog::find($id)returns null, check if the blog exists

$blog = Blog::find($id);
if (isset($blog)) $blog->update($request->all());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question