I have a contact form. There is some code from the confirm page and the final page with the 'your message has been sent' message controller code.

I need to add a couple of post data to the 'confirm' page.

How do I recieve those post data and add them to the $data array at the complete function?

/*
* confirm page
*/
public function confirm(Request $request)
{
    $rules = [];
    $this->validate($request, $rules); 
    $data = $request->all(); 

    $request->session()->put('data',$data);
    dd($request);
    return view('mail.confirm', compact("data"));
}

/*
* final page (your message has been sent page)
*/
public function complete(Request $request)
{ 
    $data = $request->session()->pull('data');
    $token = array_shift($data);
    $Contact = Contact::create($data);

    $data = session()->regenerateToken();
    return view('mail.complete');
}

1 Answers

0
thisiskelvin On Best Solutions

To add post data, you can retrieve from the $request variable using:

$request->all();

For your case:

public function complete(Request $request)
{ 
    $data = $request->session()->pull('data'); 
    $token = array_shift($data);
    $data = array_merge($data, $request->all());
    $Contact = Contact::create($data);

    $data = session()->regenerateToken();
    return view('mail.complete');
}