L5: Call to a member function function() on a non-object

Got a resourceful controller with a __contruct function to declare $project

 public function __construct(Project $project){

    $this->project = $project;
}

Then I have an update and a destroy function which gives an
Call to a member function delete() on a non-object (or update() error)

 public function edit($id)
{
    $project = $this->project->find($id);
    return view('project.edit', ['project' => $project, 'id' => 'edit']);
}


public function update(CreateProjectRequest $request, $project)
{
    $project->fill($request->input())->save();

    return redirect('project/index');
}


public function destroy($project)
{
    $project->delete();
    return redirect('project');
}

What am I doing wrong?


Source: laravel

Leave a Reply