on('n_reason', '=', 'reason.c_code'); $join->on('reason.c_type', DB::raw("CONCAT('REASON_NOTES')")); }) ->leftJoin("categories as timeTypes", function ($join) { $join->on('n_time_type', '=', 'timeTypes.c_code'); $join->on('timeTypes.c_type', DB::raw("CONCAT('TIME_TYPE')")); }) ->where('n_month', $month) ->where('n_year', $year) ->select( 'notes.id as n_id', 'n_user_id', 'n_day', 'n_month', 'n_year', 'n_time_type', 'n_reason', 'n_note', 'reason.c_name as reason_name', 'timeTypes.c_name as time_type_name' ) ->get(); } public static function getNotesByMonthAndYearAndUserId($month, $year, $userId, $idNote) { return self::where('n_reason', 'ONLEAVE')->where('n_month', $month)->where('n_year', $year) ->where('n_user_id', $userId) ->where('id', '!=', $idNote)->get(); } public static function getNotesByMonthAndYearAndUserIdAndReason($month, $year, $userId, $reason) { return self::where('n_reason', $reason)->where('n_month', $month)->where('n_year', $year) ->where('n_user_id', $userId) ->orderBy('n_day', 'asc')->orderBy('n_time_type', 'desc')->get(); } }