Danieloplata
1 year ago

Redirecting to the stored record

Posted 1 year ago by Danieloplata

Hi, In my project I would like to create a project, then redirect to it. My code to create a project works fine:

auth()->user()->createProject(
    new Project(request()->all())
);

session()->flash('message', 'Project created');

return redirect('/projects/');

To attempt to redirect to the project after creating it, I amended the code as follows:

$project = auth()->user()->createProject(
    new Project(request()->all())
);

session()->flash('message', 'Project created');

return redirect('/projects/'.$project->id);

// return route('showProject', $project->id);

Unfortunately the redirect line errors with: Trying to get property of non-object

Am I using this incorrectly?

Please sign in or create an account to participate in this conversation.