title: Laravel 5 Class 'app\Models\Colour' not found
body: <p>Up into this morning my app was working great, I've created classes in <code>app/Models</code> with no issues. I added an eloquent class called <code>Colours</code> which contains the RGB values for named Colours for use in a lookup table however the code produces a fatal error about the class not existing.</p>
  
  <p>The database is migrated and seeded correctly with no issues. However the following line of code is breaking my app</p>
  
  <pre><code>$c = Colour::query()-&gt;findOrFail(2);
  </code></pre>
  
  <p>Now why this troubles me is I have another class Wheel which is called earlier in the same class as follows</p>
  
  <pre><code>$wheel = Wheel::query()-&gt;findOrFail($data['settings']['wheel']);
  </code></pre>
  
  <p>This code runs and returns the data row as requested. Looking into other Class not found posts suggested a namespace issue, however both colours and wheel are in the same file location (<code>app\Models</code>) this is defined in the namespace tag. I've added the class as a use, added both of these as uses, I've created a model with artisan in <code>app/</code> I've tried </p>
  
  <pre><code>composer dump-autoload
  </code></pre>
  
  <p>Again no luck and class not found. I'm at a loss with this, I have other classes which call database queries in the same way on other tables which have no such issues, the content of my Wheel and Colour models are identical (except obviously the class name itself).</p>
  
  <p>Additional I've just noticed that I'm within <code>Wheel.php</code> but unlike the main class used by my app the Wheel class is an eloquent object could this prevent me from getting the datarow of another table object? How can I resolve this? Will I in essence need to create another class with my methods in and keep my wheel class as just an eloquent class?</p>
  
  <p>This model has no controller, not directly related to the wheel model. The action which calls this model from within a base controller is </p>
  
  <pre><code>public function wheel(Request $request)
  {
      $data = $request-&gt;session()-&gt;get('data');
      $model = new Wheel();
      $wheel = $model-&gt;drawWheel($data);
      return view('wheel', ['wheel' =&gt; $wheel]);
  }
  </code></pre>
  
  <p>As said up until I wanted colour names this worked fine. The Model is </p>
  
  <pre><code>&lt;?php
  
  namespace app\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Wheel extends Model
  {
  
      private function drawWheels($im, $data, $wheel)
      {
          $m = 250;
          $r = $wheel['inner_r'];
          $spokes = $data['spokes'];
          $l = $data['format'];
          foreach ($spokes as $a) {
              $oA = cos(deg2rad($l[$a['A']]));
              $aA = sin(deg2rad($l[$a['A']]));
              $xA = $m - ($r * $oA);
              $yA = $m - ($r * $aA);
              $oB = cos(deg2rad($l[$a['B']]));
              $aB = sin(deg2rad($l[$a['B']]));
              $xB = $m - ($r * $oB);
              $yB = $m - ($r * $aB);
  
              $c = Colour::query()-&gt;findOrFail(2);
              //$c = Colour::where('name', '=', strtolower($a['name']))-&gt;first();
              //$c = DB::table('colours')-&gt;where('name', strtolower($a['name']))-&gt;first();
  
              $color = imagecolorallocate($im, $c['R'], $c['G'], $c['B']);
  
              imageline($im, $xA, $yA, $xB, $yB, $color);
          }
  
          return $im;
      }
  
  }
  </code></pre>
  
  <p>Here is my app/Models/Colour class</p>
  
  <pre><code>&lt;?php
  
  namespace app\Models;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Colour extends Model
  {
      protected $guarded = ['id'];
  }
  </code></pre>
  
  <p>P.S the drawWheel function referred to in the base controller just calls the private function drawWheels (well ok it does other calls but these work and i can step through the code with xdebug and it works until it tries to load the colour row from the database)</p>
  
  <p>The full error i get is</p>
  
  <pre><code>FatalErrorException in Wheel.php line 64: Class 'app\Models\Colour' not found
  
  in Wheel.php line 64
  at FatalErrorException-&gt;__construct('message' =&gt; '', 'code' =&gt; '', 'severity' =&gt; '', 'filename' =&gt; '', 'lineno' =&gt; '', 'traceOffset' =&gt; '', 'traceArgs' =&gt; '', 'trace' =&gt; '') in HandleExceptions.php line 133
  at HandleExceptions-&gt;fatalExceptionFromError('error' =&gt; '', 'traceOffset' =&gt; '') in HandleExceptions.php line 118
  at HandleExceptions-&gt;handleShutdown() in HandleExceptions.php line 0
  at Wheel-&gt;drawAspects('im' =&gt; '', 'data' =&gt; '', 'wheel' =&gt; '') in Wheel.php line 30
  at Wheel-&gt;drawHoroscope('data' =&gt; '') in ChartController.php line 33
  at ChartController-&gt;wheel('request' =&gt; '') in Controller.php line 256
  at call_user_func_array('', '') in Controller.php line 256
  at Controller-&gt;callAction('method' =&gt; '', 'parameters' =&gt; '') in ControllerDispatcher.php line 164
  at ControllerDispatcher-&gt;call('instance' =&gt; '', 'route' =&gt; '', 'method' =&gt; '') in ControllerDispatcher.php line 112
  at ControllerDispatcher-&gt;Illuminate\Routing\{closure}('request' =&gt; '') in Pipeline.php line 139
  at call_user_func('', '') in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in Pipeline.php line 103
  at call_user_func('', '') in Pipeline.php line 103
  at Pipeline-&gt;then('destination' =&gt; '') in ControllerDispatcher.php line 114
  at ControllerDispatcher-&gt;callWithinStack('instance' =&gt; '', 'route' =&gt; '', 'request' =&gt; '', 'method' =&gt; '') in ControllerDispatcher.php line 69
  at ControllerDispatcher-&gt;dispatch('route' =&gt; '', 'request' =&gt; '', 'controller' =&gt; '', 'method' =&gt; '') in Route.php line 203
  at Route-&gt;runWithCustomDispatcher('request' =&gt; '') in Route.php line 134
  at Route-&gt;run('request' =&gt; '') in Router.php line 712
  at Router-&gt;Illuminate\Routing\{closure}('request' =&gt; '') in Pipeline.php line 139
  at call_user_func('', '') in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in Pipeline.php line 103
  at call_user_func('', '') in Pipeline.php line 103
  at Pipeline-&gt;then('destination' =&gt; '') in Router.php line 714
  at Router-&gt;runRouteWithinStack('route' =&gt; '', 'request' =&gt; '') in Router.php line 679
  at Router-&gt;dispatchToRoute('request' =&gt; '') in Router.php line 639
  at Router-&gt;dispatch('request' =&gt; '') in Kernel.php line 236
  at Kernel-&gt;Illuminate\Foundation\Http\{closure}('request' =&gt; '') in Pipeline.php line 139
  at call_user_func('', '') in Pipeline.php line 139
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in VerifyCsrfToken.php line 50
  at VerifyCsrfToken-&gt;handle('request' =&gt; '', 'next' =&gt; '') in Pipeline.php line 124
  at call_user_func_array('', '') in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in ShareErrorsFromSession.php line 49
  at ShareErrorsFromSession-&gt;handle('request' =&gt; '', 'next' =&gt; '') in Pipeline.php line 124
  at call_user_func_array('', '') in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in StartSession.php line 62
  at StartSession-&gt;handle('request' =&gt; '', 'next' =&gt; '') in Pipeline.php line 124
  at call_user_func_array('', '') in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in AddQueuedCookiesToResponse.php line 37
  at AddQueuedCookiesToResponse-&gt;handle('request' =&gt; '', 'next' =&gt; '') in Pipeline.php line 124
  at call_user_func_array('', '') in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in EncryptCookies.php line 59
  at EncryptCookies-&gt;handle('request' =&gt; '', 'next' =&gt; '') in Pipeline.php line 124
  at call_user_func_array('', '') in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in CheckForMaintenanceMode.php line 42
  at CheckForMaintenanceMode-&gt;handle('request' =&gt; '', 'next' =&gt; '') in Pipeline.php line 124
  at call_user_func_array('', '') in Pipeline.php line 124
  at Pipeline-&gt;Illuminate\Pipeline\{closure}('passable' =&gt; '') in Pipeline.php line 103
  at call_user_func('', '') in Pipeline.php line 103
  at Pipeline-&gt;then('destination' =&gt; '') in Kernel.php line 122
  at Kernel-&gt;sendRequestThroughRouter('request' =&gt; '') in Kernel.php line 87
  at Kernel-&gt;handle('request' =&gt; '') in index.php line 54
  at {main}() in index.php line 0
  </code></pre>
  
  <p>The line in Wheel at line 64 is the</p>
  
  <pre><code>$c = Colour::query()-&gt;findOrFail(2);
  </code></pre>
  
  <p>My composer.json autoload section (and the dev one) is</p>
  
  <pre><code>    "autoload": {
      "classmap": [
          "database"
      ],
      "psr-4": {
          "App\\": "app/"
      }
  },
  "autoload-dev": {
      "classmap": [
          "tests/TestCase.php"
      ]
  },
  </code></pre>