belongsTo( 'User', 'employee_id' ); } public function hourtype() { return $this->belongsTo( 'Hourtype' ); } public static function getEmployeehours( $month, $year ) { $employeehours = Employeehour::whereRaw( "MONTH(hourdate) = " . ( $month + 1 ) . " AND YEAR(hourdate) = {$year}" ) ->with( [ 'user' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); }] ) ->with( 'hourtype' ); $projecthours = Employeehour::whereRaw("MONTH(hourdate) = " . ( $month + 1 ) . " AND YEAR(hourdate) = {$year}" )->with( [ 'user' => function ( $q ) { $q->selectRaw( "id, CONCAT(firstname, ' ', middlename, ' ', lastname) AS fullname" ); }] ) ->with( 'hourtype' ); $results = $employeehours->union($projecthours)->get(); return $results; } public static function saveEmployeehour( $employeehourID, $data ) { if ( $employeehourID == 0 ) { $employeehour = Employeehour::create( $data ); $employeehourID = $employeehour->id; } else { Employeehour::whereId( $employeehourID )->update( $data ); } return $employeehourID; } }