title: Laravel pivot table record check and also check in main table
body: <p>I creating a library management project in my village library.</p>
  
  <p>I have three tables.</p>
  
  <pre><code>books
  ---------
  id
  title
  copies
  
  borrowers
  ---------
  id
  name
  
  borrows
  ---------
  id
  cleared
  book_id
  borrower_id
  </code></pre>
  
  <p>I joined the borrower table and books table in has one relation to borrows table.</p>
  
  <p>my problem is if book copies 2 available. 
  1 borrowed by some user another one copy available in a library.
  I am trying to get if one copy available in a library then show to lend view.</p>
  
  <p>this is my code.</p>
  
  <pre><code>    $books = Book::doesnthave('borrows', 'or', function($query) {
          $query-&gt;where('cleared', '=', '0');
         })-&gt;get();
      return AllBookResource::collection($books);
  </code></pre>
  
  <p>I want to get lent cleared books or book not cleared if one copy is available.</p>