title: How to use where clause with local variable without passing a parameter in Laravel
body: <p>I joined 2 tables and I want to display document_name from parent table(document_control_reviews) whose ID is currently posted in a child table (initial_approvals). The foreign key that holds the child document is 3.</p>
  <p>If I hardcode the query with the ID = 3, I get the correct result just for testing purposes. But I want the documents to be display dynamically using $id instead of 3.</p>
  <ol>
  <li><p>This hardcode test works fine when I use 3 as ID:</p>
  <pre><code> public function initial_approval(){
        $approval_files = DB::table('document_control_reviews')
                     -&gt;leftJoin('initial_approvals', 'initial_approvals.document_control_review_id', '=', 'document_control_reviews.id')
                     -&gt;leftJoin('files', 'document_control_reviews.file_id', '=', 'files.id')
                     -&gt;select('document_control_reviews.*', 'initial_approvals.*', 'files.*')
                     -&gt;where('initial_approvals.document_control_review_id', '=', 3)
                     -&gt;get();
   }
  </code></pre>
  </li>
  <li><p>But I need a dynamic ID which is a local variable $id (as showed below):</p>
  <pre><code> public function initial_approval(){
        $id = 3 //hardcoded. Here is where I'm stuck.
        $docId = DocumentControlReview::find($id);
        $approval_files = DB::table('document_control_reviews')
                     -&gt;leftJoin('initial_approvals', 'initial_approvals.document_control_review_id', '=', 'document_control_reviews.id')
                     -&gt;leftJoin('files', 'document_control_reviews.file_id', '=', 'files.id')
                     -&gt;select('document_control_reviews.*', 'initial_approvals.*', 'files.*')
                     -&gt;where('initial_approvals.document_control_review_id', '=', $id)
                     -&gt;get();
   }
  </code></pre>
  <ol start="3">
  <li>This is what I don't want. I dont need to pass any parameter. I don't need any argument in the method call.</li>
  </ol>
  <pre><code> public function initial_approval($id){
        $approval_files = DB::table('document_control_reviews')
                     -&gt;leftJoin('initial_approvals', 'initial_approvals.document_control_review_id', '=', 'document_control_reviews.id')
                     -&gt;leftJoin('files', 'document_control_reviews.file_id', '=', 'files.id')
                     -&gt;select('document_control_reviews.*', 'initial_approvals.*', 'files.*')
                     -&gt;where('initial_approvals.document_control_review_id', '=', $id)
                     -&gt;get();
   }
  </code></pre>
  </li>
  </ol>