I have 3 tables projects, users, project_time_logs. I'm trying to join them and then generate a table, however when I pull the results nothing displays. I believe is a JSON error either in my controller or route because when I pull the JSON url no data is displayed. Any thoughts are greatly appreciated.
Route
Route::get('time-log-report/data/{startDate?}/{endDate?}/{projectId?}/{employee?}', ['uses' => 'TimeLogReportController@data'])->name('time-log-report.data');
Controller
public function data($startDate = null, $endDate = null, $employeeId = null, $projectId = null) {
$timeLogs =\App\ProjectTimeLog::leftJoin('projects', 'projects.id', '=', 'project_time_logs.project_id')
->join('users', 'users.id' ,'=' ,'project_time_logs.user_id')
->select('users.name','projects.project_name','project_time_logs.start_time','project_time_logs.end_time' ,'users.name');
if(!is_null($startDate)){
$timeLogs->where(DB::raw('DATE(project_time_logs.`start_time`)'), '>=', $startDate);
}
if(!is_null($endDate)){
$timeLogs->where(DB::raw('DATE(project_time_logs.`end_time`)'), '<=', $endDate);
}
if($projectId != 0){
$timeLogs->where('project_time_logs.project_id', '=', $projectId);
}
if($employeeId != 0){
$timeLogs->where('project_time_logs.user_id', $employeeId);
}
$timeLogs->get();
return DataTables::of($timeLogs)
->editColumn('start_time', function($row){
return $row->start_time->timezone($this->global->timezone)->format($this->global->date_format.' '. $this->global->time_format);
})
->editColumn('end_time', function($row){
if(!is_null($row->end_time)){
return $row->end_time->timezone($this->global->timezone)->format($this->global->date_format.' '.$this->global->time_format);
}
else{
return "<label class='label label-success'>".__('app.active')."</label>";
}
})
->editColumn('name', function($row){
return ucwords($row->user->name);
})
->editColumn('project_name', function($row){
return ucwords($row->project->project_name);
})
->editColumn('total_hours', function($row){
$timeLogs = intdiv($row->total_minutes, 60).' hrs ';
if(($row->total_minutes % 60) > 0){
$timeLogs= ($row->total_minutes % 60).' mins';
}
return $timeLogs;
})
->rawColumns(['end_time', 'start_time', 'name','project_name'])
->make(true);
}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2PuTvbH
via IFTTT
Aucun commentaire:
Enregistrer un commentaire