here is my code
public function taskTypes()
{
ini_set('max_execution_time', 5000);
ini_set('memory_limit', '5000M');
$this->middleware('auth');
if (!Auth::user()->can('tasks_types'))
abort(403);
$page_title = 'Tasks';
$userID = Auth::user()->id;
//echo $userID;die;
$projects = ['' => 'Select Project'] + Projects::lists('project_name', 'id')->all();
$sections = ['' => 'Select Section'] + Department::lists('department_code', 'id')->all();
$task_status = ['' => 'Select Task Status','Ongoing' => 'Ongoing','Completed' => 'Completed','Overdue' => 'Overdue'];
$users = User::lists('emp_name', 'id')->all();
if((Auth::user()->hasRole('superadmin')) || (Auth::user()->hasRole('manager'))|| (Auth::user()->hasRole('administrator ')))
$ongoingTaskData = Task::where('status', '=', 'Ongoing')
->orderBy('id', 'DESC')
->get();
else {
$ongoingTaskData = Task::whereHas('users', function ($query) {
$query->where('task_user.user_id', '=', Auth::user()->id);
})
->where('status', '=', 'Ongoing')
->orderBy('id', 'DESC')
->get();
}
if((Auth::user()->hasRole('superadmin')) || (Auth::user()->hasRole('manager'))|| (Auth::user()->hasRole('administrator ')))
$pendTaskData = Task::where('status', '=', 'Overdue')
->orderBy('id', 'DESC')
->get();
else {
$pendTaskData = Task::whereHas('users', function ($query) {
$query->where('task_user.user_id', '=', Auth::user()->id);
})
->where('status', '=', 'Overdue')
->orderBy('id', 'DESC')
->get();
}
if((Auth::user()->hasRole('superadmin')) || (Auth::user()->hasRole('manager'))|| (Auth::user()->hasRole('administrator '))) {
$completedTaskData = Task::where('status', '=', 'Completed')
->orderBy('id', 'DESC')
->get();
//set for view
$enable = 'display:block';
$colNum = '3';
}
else {
$completedTaskData = Task::whereHas('users', function ($query) {
$query->where('task_user.user_id', '=', Auth::user()->id);
})
->where('status', '=', 'Completed')
->orderBy('id', 'DESC')
->get();
//set for view
$enable = 'display:none';
$colNum = '4';
}
//echo "<pre>";print_r($ongoingTaskData);die;
return view('tasks.tasks_info', compact('page_title','sections','task_status','enable','colNum','projects', 'users', 'ongoingTaskData', 'pendTaskData', 'completedTaskData'));
}
for each ongoing task check if expiration date is greater than Carbon::now() carbon has a function for this i believe
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community