Support the ongoing development of Laravel.io →
posted 5 years ago
Laravel
Last updated 2 years ago.
0

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'));
    }
0

for each ongoing task check if expiration date is greater than Carbon::now() carbon has a function for this i believe

0

Sign in to participate in this thread!

Eventy

Your banner here too?

malik maliksbbu Joined 18 Mar 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.