8

I just created a simple app in Laravel 4 and when I create a model, I get an exception that it's not found.

// /app/models/Worker.php:
<?php

class Worker extends Eloquent {}

And then in the Controller

var_dump(Worker::find(1));

This gives me Error: Class 'Worker' not found. What am I doing wrong? This used to work in Laravel 3 and also watching the screencasts it seems like this should work.

BenjaminRH
  • 11,974
  • 7
  • 49
  • 76
duality_
  • 17,738
  • 23
  • 77
  • 95

2 Answers2

24

Anytime you create a new class file in L4 run this command.

php composer dump-autoload
anthony.c
  • 481
  • 4
  • 15
  • 1
    "Just great". And I thought there's surely something that I did wrong. Now it works. I think I remember hearing that on one of the nettuts screencasts, but, naturally forgot. But now I got another problem, which I'll post another question for :). – duality_ Jan 11 '13 at 18:46
  • Here's the other problem: http://stackoverflow.com/questions/14284854/laravel-4-eloquentfind-doesnt-work – duality_ Jan 11 '13 at 18:57
  • 2
    I think you've got them mixed up.. composer dump-autoload.. php artisan dump-autoload – Joeri Mar 28 '14 at 08:56
  • so... depending on the context of which you setup composer, This could in fact be php composer.phar dump-autoload, php artisan clear-compiled, or composer dump-autoload (globally installed composer) – anthony.c Jan 29 '16 at 02:31
5

I think there are two commands to get the autoload started:

$ composer dump-autoload  

and

$ php artisan dump-autoload

Seems composer dump-autoload is to let composer create autoloads as defined in the composer.json files. And php artisan dump-autoload glues all the composer dump-autoloads ( also from vendors and workbenches ) together.

Joeri
  • 2,214
  • 24
  • 24