title: Laravel best practice for get data from DB
body: <p>I'm confused about the best way to get data from DB. I have this controller (Task) that get from Task model the tasks of each customers. What's the best way to get these data?</p>
  
  <h2>1° Example</h2>
  
  <p>In this example I have a "general" function (getTasksCompany) that join the tables (Task and Companies). The showTasks call this function and then use where clause for get only tasks with customer code = 000001</p>
  
  <pre><code>    public function showTasks() {
              $tasks = $this-&gt;getTasksCompany()-&gt;where("company_code", "=", "000001")-&gt;get();
  
              dd($tasks);
          }
  
  public function getTasksCompany() {
          $tasks = Task::join("companies AS c", "c.code", "=", "company_code");
  
          return $tasks;
      }
  </code></pre>
  
  <h2>2° Example</h2>
  
  <p>In this example I have a "specific" function that get tasks from the code in the passed as argument.</p>
  
  <pre><code>public function showTasks2() {
          $tasks = $this-&gt;getTasksFromCompany("000001");
  
          dd($tasks);
      }
  
  public function getTasksFromCompany($company_code) {
          $tasks = Task::join("companies AS c", "c.code", "=", "company_code")-&gt;where("company_code", "=", $company_code)-&gt;get();
  
          return $tasks;
      }
  </code></pre>
  
  <h2>3° Example</h2>
  
  <p>In this example I have a "general" function (getTasksCompany) that join the tables (Task and Companies) and I use the scope defined from Task model to filter the tasks.</p>
  
  <pre><code>public function showTasks3() {
          $tasks = $this-&gt;getTasksCompany()-&gt;company("000001")-&gt;get();
  
          dd($tasks);
      }
  
   public function getTasksCompany() {
          $tasks = Task::join("companies AS c", "c.code", "=", "company_code");
  
          return $tasks;
      }
  
  public function scopeCompany($query, $company_code) {
          return $query-&gt;where("company_code", "=", $company_code);
      }
  </code></pre>
  
  <p>My question is, what's the good practice to do? And Why?</p>