title: Laravel: Creating a common function for all models
body: <p>In my laravel(7.x) application, I have a common functionality to show the count of all the active and inactive records in all the modules. Therefore, I am obligated to repeat the same functionality on every module.</p>
  
  <p>For example: <code>Device, DeviceType, DeviceCompany, etc</code> models have a same method called <code>_getTotal</code> and everywhere that <code>_getTotal</code> method is doing the same work.</p>
  
  <p>Device.php</p>
  
  <pre class="lang-php prettyprint-override"><code>class Device extends Model
  {
      protected $table = 'devices';
  
      ...
  
      public function _getTotal($status = \Common::STATUS_ACTIVE)
      {
          return self::where([
              'status' =&gt; $status
          ])-&gt;count() ?? 0;
      }
  }
  </code></pre>
  
  <p>DeviceType.php</p>
  
  <pre class="lang-php prettyprint-override"><code>class DeviceType extends Model
  {
      protected $table = 'device_types';
  
      ...
  
      public function _getTotal($status = \Common::STATUS_ACTIVE)
      {
          return self::where([
              'status' =&gt; $status
          ])-&gt;count() ?? 0;
      }
  }
  </code></pre>
  
  <p>I tried to put this method in the <code>Base Model</code> but I think may not be a good practice. Am I right..?<br>
  Is there any way to make this method <code>_getTotal</code> a common method for all the modules..?</p>