Skip to content

Instantly share code, notes, and snippets.

@marufmax
Last active July 26, 2018 03:40
Show Gist options
  • Save marufmax/637aa5d3fcbb927a16f6bbb419e1f956 to your computer and use it in GitHub Desktop.
Save marufmax/637aa5d3fcbb927a16f6bbb419e1f956 to your computer and use it in GitHub Desktop.
Eloquent with raw sql and eqlouent where join select
<?php
//Raw SQL
$present = DB::select(DB::raw("SELECT count(had.emp_id) as present FROM hta_emp_personal hep
INNER JOIN hta_attendance_details had ON hep.emp_id=had.emp_id
AND had.att_date='2018-07-07 00:00:00'
AND had.status='P'"));
// ORM
$present = DB::table('hta_attendance_details')
->join('hta_emp_personal', 'hta_emp_personal.emp_id', '=', 'hta_attendance_details.emp_id')
->select('hta_attendance_details.*', 'hta_emp_personal.emp_id')
->where([
['hta_attendance_details.status', 'P'],
['hta_attendance_details.att_date', '2018-07-07 00:00:00']
])
->count();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment