xxxxxxxxxx
/*
|===========================================================
| How to add custom columns in Yajra Datatables -- METHOD 2
|===========================================================
*/
xxxxxxxxxx
/*
|===========================================================
| How to add custom columns in Yajra Datatables --
|===========================================================
*/
// METHOD-1
public function index()
{
try {
$vendors = User::where('role_id', 2)->get();
$vendors_count = count($vendors);
$active_vendors_count = $vendors->where('status',true)->count();
$inactive_vendors_count = $vendors->where('status',false)->count();
$featured_vendors_count = $vendors->where('featured',true)->count();
if(request()->ajax()) {
return datatables()->of(User::where('role_id', 2)->orderBy('id', 'ASC'))
// ->addColumn('profile_image', function ($artist) {
// $url= asset('https://cdn.traveltripper.io/site-assets/192_680_14834/media/2018-04-20-004600/mts-superstores-times-square-disney.jpg');
// return '<img src="'.$url.'" border="0" width="40" class="img-rounded" align="center" />';
// })
->addColumn('profile_image', 'admin.vendors.ydt-partials.profile-image')
->addColumn('status', 'admin.vendors.ydt-partials.status-button')
->addColumn('featured', 'admin.vendors.ydt-partials.featured-button')
->addColumn('action', 'admin.vendors.ydt-partials.action-buttons')
->rawColumns(['profile_image','status','featured','action'])
->addIndexColumn()
->make(true);
}
return view('admin.vendors.index')->with([
'vendors' => $vendors,
'vendors_count' => $vendors_count,
'active_vendors' => $active_vendors_count,
'inactive_vendors'=> $inactive_vendors_count,
'featured_vendors'=> $featured_vendors_count,
]);
}
catch (\Throwable $th) {
throw $th;
}
}