ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • laravel query builder 에서 사용되는 exists 및 doesntExist 메서드
    백엔드 2024. 1. 14. 14:45

    1. exists 메서드 - 값의 존재 확인:

        if (DB::table('posts')->where('id', 999)->exists()) {
            echo "Woohoo! I have found a match.";
        } else {
            echo "R. I have not found a match.";
        }


        이 코드는 id가 999인 게시물이 존재하는지 확인합니다.

    2. doesntExist 메서드 - 값의 미존재 확인:

        if (DB::table('posts')->where('id', 1)->doesntExist()) {
            echo "Woohoo! I have not found a match.";
        } else {
            echo "R. I have found a match.";
        }

        이 코드는 id가 1인 게시물이 존재하지 않는지 확인합니다. 

     

     

    댓글

Designed by Tistory.