📜  laravel 数据表格式日期列 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:54.026000             🧑  作者: Mango

代码示例1
$projects = Project::select('id', 'name', 'date_start', 'date_end');
return Datatables::of($projects)
  ->editColumn('date_start', function ($request) {
    return $request->date_start->format('Y-m-d'); // human readable format
  })
  ->editColumn('date_end', function ($request) {
    return $request->date_end->format('Y-m-d'); // human readable format
  })
  ->filterColumn('date_start', function ($query, $keyword) {
    $query->whereRaw("DATE_FORMAT(date_start,'%Y-%m-%d') like ?", ["%$keyword%"]); //date_format when searching using date
  })
  ->filterColumn('date_end', function ($query, $keyword) {
    $query->whereRaw("DATE_FORMAT(date_end,'%Y-%m-%d') like ?", ["%$keyword%"]); //date_format when searching using date
  })
  ->make(true);