title: Laravel model not found
body: <p>We have a model <code>App\Models\Tag</code>. In a helper class we're doing:</p>
  
  <pre><code>&lt;?php 
  
  namespace App\Helpers;
  
  use App\Models\Tag;
  
  
  class Helper {
  
      /**
      * Get tag
      *
      **/
      public static function tag($path){
  
              return Tag::where('path', '=', $path)-&gt;first();
  
      }
  
  
  }
  </code></pre>
  
  <p>This gives error:</p>
  
  <pre><code>FatalErrorException in Model.php line 780: 
  
  Class 'Tag' not found
  </code></pre>
  
  <p>Even using <code>App\Models\Tag::where('path', '=', $path)-&gt;first()</code> gives an error:</p>
  
  <pre><code>FatalErrorException in Helper.php line 15: 
  
  Class 'App\Helpers\App\Models\Tag' not found
  </code></pre>
  
  <p>What's most strange is that we can use <code>App\Models\Tag</code> from controller without a problem. So, problem seems to be on this helper class and not the model. Any idea?</p>
  
  <p><strong>Tag.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Tag extends Model {
  
          // database table
          protected $table = 'tags';
  
  }
  
  ?&gt;
  </code></pre>
  
  <p><strong>Edit 1</strong></p>
  
  <p>The model <strong>Tag.php</strong> was manually added instead of using <code>artisan</code>. So, there's a chance it's missing from classes map. From the suggestion on <a href="https://stackoverflow.com/a/35142715/1008916">https://stackoverflow.com/a/35142715/1008916</a> we tried <code>composer dump-autoload -o</code> but that didn't help.</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>We eventually traced the issue to a different model related to Tag.php. The lines of code causing the problem were:</p>
  
  <pre><code>        $tag = Tag::where('path', '=', $path)-&gt;first();
          if ($tag == null) {
              $tagLet = TagLet::where('path', '=', $path)-&gt;first();
              if ($tagLet != null) {
                  $tag = $tagLet-&gt;tag;
              }
          }
  </code></pre>
  
  <p>When  a model throws an error Laravel does not give line number where the error occurred, so we identified the 1st occurrence of Tag as cause while the real cause was last occurrence (<code>$tag = $tagLet-&gt;tag;</code>).</p>
  
  <p>TagLet.php had: </p>
  
  <pre><code>public function tag()
  {
      return $this-&gt;belongsTo('Tag');
  }
  </code></pre>
  
  <p>As suggested by @Rodrane &amp; @SauminiNavaratnam the solutions is to use 'App\Models\Tag' instead of 'Tag'     </p>
  
  <pre><code>public function tag()
  {
      return $this-&gt;belongsTo('App\Models\Tag');
  }
  </code></pre>