I want pass data set through a Laravel URL. This is my code. First I pass my dataset to JavaScript and next I call the URL.
JavaScript Code
<script type="text/javascript">
function divClick(roomState, roomCode){
// Your code here
//window.alert(roomCode); //print_output well
//value_url out put as following
//room_detail/{"id":"24","room_code":"H5016","roomState":"UnAvailable","hotelId":"5","roomTypeId":"7","created_at":"-0001-11-30 00:00:00","updated_at":"2015-11-04 06:52:09"}
//call new page
window.location.href ="{{url('room_detail/roomCode')}}";
}
</script>
routes.php file code
Route::any('room_detail/{roomDetail}', function() {
return view('pages/room_details/roomMap/single_room_map_detail', compact('roomDetail'));
});
========view.blade.php========================================
I use this code to print passing value.
<section class="content">
<div class="row">
<div class="box box-warning">
<div class="gap">
<div class="box-body">
{!! $roomDetail !!}
</div><!-- /.box -->
</div><!-- /.box -->
</div><!-- /.row -->
</div>
</section><!-- /.content -->
When the view gets rendered, I get this error:
Undefined variable: roomDetail
Expect some expert help , to pass this data set though a URL .
Your route needs to look like this (notice the variable in the function call):
Route::any('room_detail/{roomDetail}', function($roomDetail) {
return view('pages/room_details/roomMap/single_room_map_detail', compact('roomDetail'));
});
Also you need to pass the variable correctly to the url like this:
window.location.href = "{{url('room_detail')}}" + "/" + roomCode; // maybe you can discard the slash after room_detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With