mardi 10 mai 2016

Date subtraction from columns in laravel 5

i have to two column, durasi and mulai and I want the total column reflect durasi - mulai .

this is my table

this is my controller.

public function postSimpanTambah()
    {
        $simpan= array();
        $simpan['nama']=Request::input('nama');
        $simpan['tanggal']=Request::input('tanggal');
        $simpan['deskripsi']=Request::input('deskripsi');
        $simpan['mulai']=Request::input('mulai');
        $simpan['durasi']=Request::input('durasi');
        $simpan['total'] = \Carbon\Carbon::createFromFormat('H:i', Request::input('durasi')) - \Carbon\Carbon::createFromFormat('H:i', Request::input('mulai'));


        DB::table('lembur_karyawan')->insert($simpan);
        echo "<script language='javascript'>
                alert('Berhasil menambahkan data');
                document.location='../user';
               </script>";
    }

this is my view :

<h3>Tambah User</h3>
                <hr>
            <form method="post" action="<?php echo url('user/simpan-tambah') ?>" enctype="multipart/form-data">
            <div class="form-group">
                  <input type="hidden" name="_token" value="}" />
                  <input type="hidden" class="form-control" name="id" placeholder="Tambahkan Id">
            </div>

            <div class="form-group">
                <label for="inputIsiBerita"> Nama:</label>
                <input type="text" class="form-control" name="nama" value="<?php echo  Auth::user()->name. '';?>" readonly>
            </div>

            <div class="form-group">
                <label for="inputIsiBerita"> Tanggal:</label>
                <input type="date" class="form-control" name="tanggal" placeholder="Tambahkan Tanggal">
            </div>

            <div class="form-group">
                <label for="inputIsiBerita"> Deskripsi:</label>
                <input type="text" class="form-control" name="deskripsi" placeholder="Tambahkan Deskripsi">
            </div>

            <div class="form-group">
                <label for="inputIsiBerita"> Mulai:</label>
                <input type="time" class="form-control" name="mulai" value="17:00" readonly>
            </div>

            <div class="form-group">
                <label for="inputIsiBerita"> Durasi:</label>
                <input type="time" class="form-control" name="durasi" placeholder="Tambahkan Durasi">
            </div>


            <div class="form-group">
                    <div class="controls">
                    <button type="submit" class="btn btn-primary">Kirim</button>
                    <button type="reset" class="btn btn-inverse">Reset</button>
                    <button type="button" onclick='location.href="<?php echo url('admin') ?>"' class="btn btn-inverse">Batal</button>
                    </div>
            </div>  

            </form>

and when i try to run i always get respond: Object of class Carbon\Carbon could not be converted to int

whats should i do ? have idea?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire