vendredi 26 juillet 2019

Laravel Get value from form to date('request->date')

I just tried using the pop-up form with Laravel.

I want to get a value in the "start" and "end" columns so that it can be retrieved by the controller.

This is a pop-up form that contains the "start" and "end" columns.

Views

<div class="modal fade col-xs-12 col-sm-12 col-md-12 col-lg-12" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
            </div>
            <div class="modal-body">
                <form id="frmProducts" name="frmProducts" class="form-horizontal" novalidate="">
                    <div class="">
                        <div class="form-group">
                            <label class="col-form-label">Dari:</label>
                            <input type="date" name="start" class="form-control" value="yyyy-mm-dd">
                            <label class="col-form-label">Sampai:</label>
                            <input type="date" name="end" class="form-control" value="yyyy-mm-dd">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="" id="export" class="btn btn-outline-success mb-3">PDF</a>
            </div>
        </div>
    </div>
</div>
----
$(document).on('click','.open_modal',function(){
        var url = "sub.domain.com/folder";
        $.get(url, function (reservasi) {
            console.log(reservasi);
            $('#start').val($request->start);
            $('#end').val($request->end);
            $('#export').val("test");
            $('#myModal').modal('show');
        }) 
    });

Controller

public function test(Request $request)
    {
        $start = date($request->start);
         $end = date($request->end);
        $reservasi = Reservasi::join('kamar','reservasi.idkamar','=','kamar.id')
        ->select('reservasi.id','kamar.name as kamar','reservasi.konfirmasi', 'reservasi.created_at')
        ->whereBetween('reservasi.created_at', [$start, $end])
        ->orderBy('reservasi.konfirmasi','ASC')
        ->get();
dd($reservasi);

    }



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Oo0kuQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire