Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Yomamen's avatar

How do i pass form data after redirecting to view

So im making a booking system website (a simple one) using laravel 5.5.

Here's how it goes.

A user access a profile with a form booking inside the profile -> user submitting booking enquiry -> user will get notified by emails with all the booking form data submitted previously

I have successfully achieved in passing all the data to the email but i have trouble passing all the data to the generated "/receipt" view.

What im trying to achieve is a "/receipt" page where the user gets a feedback that the booking enquiry has been submitted. This will only be generated once, so if the user refreshes the page it will be empty.

What i have right now

Controller

$enquiryID = strtoupper(substr(md5(microtime()), 0, 7)) . $user->id;
$bookingEnquiry->id = $enquiryID;
$bookingEnquiry->user_id = $user->id;
$bookingEnquiry->name = $request->input('bookingName');
$bookingEnquiry->phone_number = $request->input('bookingContact');
$bookingEnquiry->email = $request->input('bookingEmail');

session()->flash('message', 'Your booking enquiry has been sent!');
return redirect('/receipt')->with(compact('bookingEnquiry', 'enquiryID', 'user', 'request'));

Route

Route::get('/receipt', function () {
    return view('bookingEnquiries.receipt');
});

I'd like to pass name, phone, email to the 'bookingEnquiries.receipt' page once.

Also, can i generate the view inside the controller ? Seems to be a bit neater.

0 likes
1 reply
bobbybouwmann's avatar

Yes of course you can create the view in the controller

// Routes
Route::get('/receipt', 'SomeController@show');

// SomeController.php
public function show()
{
    return view('bookingEnquiries.receipt');
}

You can pass any value to the view which you can use inside that view. You can simply retrieve it from the database or session or whatever.

Take a look here: https://laravel.com/docs/5.5/controllers

Let me know if you have more questions

Please or to participate in this conversation.