Laravel Eloquent Column Editing with Yajra Datatables

20-07-2020

Laravel Eloquent Column Editing with Yajra Datatables

class PrivatePackageController extends AppBaseController
{
    public function index(){
        try {
            $model=PrivatePackage::query();
            $result=DataTables::eloquent($model)
                ->setTotalRecords(100)
                ->editColumn('price', function(PrivatePackage $privatePackage) {
                    return MoneyUtil::twoDecimalNumber($privatePackage->price/100);
                })
                ->toArray()['data'];

            return $this->sendResponse($result,'');
        }catch (\Exception $e){
            Log::error($e->getMessage());
            return $this->sendError('Beklenmeyen bir hata oluştu');
        }
    }
}

Example Request:

http://localhost:8000/packages?columns[0][name]=id&order[0][column]=0&order[0][dir]=asc

© 2019 All rights reserved. Codesenior.COM