Sigo iniciandome en el mundillo de laravel, pero a cada paso que doy me encuentro 2 o 3 obstaculos.
El caso es ue intento hacer una peticion ajax para que no tenga que recargar la pagina para devolverme unos valores de base de datos. he conseguido que haga una busqueda por fecha, pero la duda que tengo es poco macer para mandarle 2 parametros y no solo la fecha.
Es posible?
Código:
public function show($date, Request $request) { $records = Records::where('date', '=', \Carbo\Carbon::parse($date)->format('Y-m-d'))->get(); $hours= array("09:00:00","10:00:00","11:00:00","12:00:00","13:00:00","14:00:00","15:00:00","16:00:00","17:00:00","18:00:00","19:00:00","20:00:00","21:00:00","22:00:00","23:00:00"); $cont=0; foreach ($hours as $hour) { foreach ($records as $record) { if($record->hour==$hour){ $result[$cont]=true; break; }else {$result[$cont]=false;} } $cont++; } if ($request->ajax()) { return response($result); } }
Código:
<div id="datepicker" class="col-md-4"></div> {!! Form::open(['route'=> ['records.book.show', ':DATE'], 'method' => 'GET', 'id' => 'installation']) !!} {!! Form::close() !!} <script> $('#datepicker').datepicker({ dateFormat: "dd-mm-yy", onSelect: function(dateText, inst) { var form = $('#installation'); var url = form.attr('action').replace(':DATE', dateText); url += "?installation='fronton1'"; var data = form.serialize(); $.get(url, data, function(result){ var content=""; var hours= ["09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"]; for (var i=0; i <= result.length-1; i++) { if(result[i]==true){var estado='ocupado'; var clase='class="danger"';}else{var estado='libre'; var clase='class="success"';} content += "<tr "+ clase +">"; content += "<td> " +hours[i] + "</td>"; content += "<td> " +estado + "</td>"; content += "</tr>"; } document.getElementById('records_table').innerHTML=content; }).fail(function(){ alert('error'); }); } }); </script>