dd(request());
Works for me. You can also do dd(request()->toArray()), in order to display input fields only. Hope that helps!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying to setup a stripe payment option. The problem I am stuck at atm is that I want to do this as a 2-step process, where I first validate all the information filled out in the form and redirect to a new view where I take care of the payment and storing information in the database.
Problem is I cant figure out how to pass the variables in my first function to the second function.
This is the first function, for the validation process:
public function validator(Request $request)
{
$price = Course::where('kursId', request('courseId'))->value('pris')*100;
try {
$data = $request->validate([
'courseEvent' => 'required|max:11',
'enrollmentFirstName' => 'required|max:255',
'enrollmentLastName' => 'required|max:255',
'enrollmentBirthDate' => 'required|max:255',
'enrollmentAddress' => 'required|max:255',
'enrollmentAddressNr' => 'required|max:255',
'enrollmentEmail' => 'required|max:255',
'enrollmentPhone' => 'required|max:255',
'companyName' => 'required|max:255',
]);
} catch (\Exception $ex) {
\Session::flash('flash_message_feil','Ops, det er noe som ikke er fylt riktig ut i skjemaet!!!');
return redirect()->back();
}
return view('enrollmentPrivate.payment', compact('price', 'data'));
}
in my view I can use the variables just fine like this:
<form action="/charge" method="post">
{{ csrf_field() }}
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="{{ env('STRIPE_PUB_KEY') }}"
data-amount="{{ $price }}"
data-label="Betal med kort"
data-name="Stripe Demo"
data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
data-locale="auto"
data-currency="nok">
</script>
</form>
But when I try to use them in the next function for the actual charging, I get "undefined variable" error. second function:
public function charge(Request $request)
{
dd($data);
}
This is my routes: (dont know how relevant they are tho)
Route::post('/validate', 'EnrollmentPrivateController@validator');
Route::post('/charge', 'EnrollmentPrivateController@charge');
I will be very grateful for any help I can get with this! :)
Please or to participate in this conversation.