no need for sessions. Your next button submits the first form to the controller with a Post route, you can then pass whatever you need from that form into the next view.
How to pass data from one view to another using session?
I have a conference details page and a page to register in the conference.
In the conference details page, the user can select through a select menu how many registrations want from each registration type available for the conference and then click in the "Next" button to go to the registration page.
My doubt is how to pass data (quantity of each registration type selected) from conference details page to the registration page? Because in the registration page is necessary to show a summary of the quantity of registration selected by the user in the conference details page, a summary like:
registration_types quantity price subtotal
rt01 2 5.00$ 10.00$
rt02 1 10.00$ 10.00$
TOTAL 20.00$
For what Im understanding is necessary to use sessions for this context, but I dont find any example of using sessions to pass data from another page like this context. Do you know how this can be achieved?
The structure I have is:
FrontEndController that has a show method to show the conference details page:
public function show($id, $slug){
$conf = Conference::where('id', $id)->first();
$registrationTypes = RegistrationType::where('conf_id', $conf->id)->get();
return view('confs.show')->with('conf',$conf)->with('registration_types', $registrationTypes);
}
The route for this method above:
Route::get('/conference/{id}/{slug?}', [
'uses' => 'FrontEndController@show',
'as' =>'confeerences.show'
]);
In the conference details page I have select menus so the user can select how many tickets want from each registration type:
<div>
<div>
<span>Registration</span>
<span>Quantity</span>
<span>Price</span>
</div>
<div>
<ul>
@foreach($registration_types as $rtype)
<li>
<div>
<span>{{$rtype->name}}</span>
</div>
<form>
<select
id="rtype_{{ $rtype->id }}" data-price="{{ $rtype->price }}" name={{ $rtype->name }}>
<option selected></option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
</form>
<span>X {{$rtype->price}}€</span>
</li>
@endforeach
<li>
<div>
<span>TOTAL</span>
</div>
<span>0.00€</span>
</li>
</ul>
</div>
<div>
<a href="{{route('conferences.registration', ['id' => $conf->id, 'slug' => $conf->slug])}}">Next</a>
</div>
</div>
After the user selects the number of registrations for each registration type that he wants he can click "Next" to go to the registration page.
So I created this route:
Route::get('/conference/{id}/{slug?}/registration', [
'uses' => 'FrontEndController@registration',
'as' =>'conferences.registration'
]);
And in FrontEndController I have the method:
public function registration(){
return view('conferences.registration');
}
Registrtion page summary, that is static for now in the registration.blade.php file:
<div>
<div>
<span>Summary</span>
</div>
<div>
<ul>
<li>
<span>Registration Type</span>
<span>Quantity</span>
<span>Price</span>
<span>Subtotal</span>
</li>
<li>
<span>rt01</span>
<span>2</span>
<span>5.00$</span>
<span>10.00$</span>
</li>
<li>
<span>rt02</span>
<span>1</span>
<span>10.00$</span>
<span>10.00$</span>
</li>
<li>
<span>TOTAL</span>
<span>20.00€</span>
</li>
</ul>
</div>
</div>
Please or to participate in this conversation.