Pat
Pat

Reputation: 132

Laravel Form Return then Redirect

I'm still getting to grips with laravel, and I imagine this has a straightforward fix, but I can't seem to find anything for it. I want submit my form, have the data returned through the create and then redirect to another page rather than displaying my form results. Currently it just returns an empty page with the email and name variables and adds it to the db.

I've tried the below in adduser controller but it doesn't action the create function through my db and just redirects me.

   return Child::create([
        'name' => $request->input('name'),
        'email' => $request->input('email'),           
   ]) && Redirect::to('/anotherpage');

Do I have to do something with my controller or can this be done with a variant of the above?

Upvotes: 0

Views: 224

Answers (1)

Tharaka Dilshan
Tharaka Dilshan

Reputation: 4499

You can use redirect() function with data

$child = Child::create([
    'name' => $request->input('name'),
    'email' => $request->input('email'),           
]);

// in route() function first parameter is the route name,
// second parameter is the data array.
return redirect(route('another_page', ['child' => $child]));

Upvotes: 1

Related Questions