samedi 25 août 2018

get id of table in laravel using datatable

Hello friends I have two database table 1. Quotations 2. Clients

Issue 1 :

I have 4 entries in Quotations table

ID         customer_id      Exp_date
1            1               2018-08-24
2            1               2018-08-26
3            2               2018-08-24
4            2               2018-08-23

I want to fetch data where exp_date < 2018-08-25 but customer_id must be unique. In case any customer_id has exp_date > 2018-08-25 then this customer_id should not be fetched.

Currently I am using the following Query

$cur_date = date('Y-m-d');
   $clientTemp = DB::table('clients')->where('quotations.exp_date','<',$cur_date)
     ->join('quotations','quotations.customer_id','=','clients.id')
     ->groupBy('customer_id')
      ->get()
       ->map(function ($clientTemp) {
        return [
            'id' => $clientTemp->id,
            'hash' => $clientTemp->hash,
            'name' => $clientTemp->first_name.' '.$clientTemp->last_name,
            'email' => $clientTemp->email,
            'mobile' => $clientTemp->mobile
        ];
    });

It is returning the data of row ID 2 which Should Not be there.

Issue 2

I am fetching this data to data tables. I am using the following code :

return $datatables->collection($clientTemp)

        ->addColumn('actions', '@if(Sentinel::inRole(\'admin\'))
                                <a href="" title="">
                                        <i class="fa fa-fw fa-pencil text-warning "></i> </a>
                                @endif')

        ->removeColumn('id')
        ->rawColumns(['actions'])->make();

In addColumn a href code I am using variable $id where I want to show the id of clients table. currently it is showing the Id of quotations table.

Please help me to solve both the issues



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire