如何选择Laravel 5中过去30天加入表用户和员工的数据

时间:2015-08-29 18:12:06

标签: php laravel-5

recent_employees =DB::table('users.created_at')
        ->join('employees', 'users.id', '=', 'employees.user_id')

        ->select('users.id', 'name','created_at')
        ->where DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= 'created_at';
        ->get();

2 个答案:

答案 0 :(得分:0)

试试这个

recent_employees = DB :: table('users as u') - &gt; join('employees as e','users.id','=','employees.user_id')

    ->select('u.id', 'e.name','u.created_at')
    ->whereRaw('DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= 'created_at')
    ->get();

答案 1 :(得分:0)

      $date = date("Y-m-d");// current date
    $dates = date("Y-m-d", strtotime(date("Y-m-d", strtotime($date)) . " -1 
      month"));
$count_student = DB::table('students')->count();

       $recent_students =DB::table('users')
        ->join('students', 'users.id', '=', 'students.user_id')

        /*->select('users.id', 'name','users.created_at')*/
        ->where('created_at', ">=", $dates)
        ->get();