atmaboy
6 months ago

How To Only Return Collections Where no other relationship

Posted 6 months ago by atmaboy
    use App\User;
    use App\Task;
    use App\Join;
    
    public function tasks(Request $request)
    {
        $user = auth::user();
            $query = Task::query();

        $query->with('User')->with('task_type');
        $q = $query->paginate($tasksPerPage);
        
           foreach($q as $task) {
           $status = Join::where('user_id',$user->id)->where('task_id',$task->id)->first();
           if($status['user_id'] == $user->id){
               $task->current_status = false;
           }
           else{
               $task->current_status = true;
           }
        }
        return $q;
        

How return only task where not found record in other relation Join model ?

or return only records with current_status true and pagination

Please sign in or create an account to participate in this conversation.