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

akashbd's avatar

How to get dropdown select value session in another page in Laravel 8

I wish I had a few options in one form. The user will select the report type from this form, and according to that selected value, I want to show the input field in a different form. I have been trying to do this for two days but I can't do it. It would be very helpful if someone could help

This is my form one code

<form action="{{url('prepare/create/report')}}" method="post">
<label for="">Report Type</label>
<select name="report_type">
@foreach($report_type as $data)
<option value="{{$data->id}}">{{$data->name}}</option>
@endforeach
</select>
</form>

I want to get the above form dropdown value session data in this form

<form action="{{url('start/create/report')}}" method="post">
@csrf
@if($report->report_type == '1001')
<label for="">Student Name</label>
<input type="text" name="name" value="">
@else
<label for="">Teacher Name</label>
<input type="text" name="name" value="">
@endif
</form>

I'm new to Laravel and don't really understand the season so I don't understand how my controller code will be.

This is my route code

Route::get('/prepare/create/report', [AdminController::class, 'PrepareCreateReport']);
Route::post('/prepare/create/report', [AdminController::class, 'StoreCreateReport']);
Route::get('/create/report/start', [AdminController::class, 'StartReportCreation'])->name('create.report');
0 likes
4 replies
salmankhan2482's avatar

call a function on report_type change and store the value in session and then in another page get the value from the session. on form submit clear the session in the controller.

2 likes
akashbd's avatar

@salmankhan2482 Please sir can you show me how Can I call a function and store the value? I'm new so I can't understand.

salmankhan2482's avatar

@akashbd do you know an ajax call ? you should make an ajax call on the change of the select and then go to controller and set the value of session there and then you can access that value in the next page.

Please or to participate in this conversation.