0

I want to create a BaseMigration class like in this tutorial. I've saved it as app/database/migrations/BaseMigration.php and extend it in my other migrations, but when I try to run my migrations via php artisan migrate I get the following error:

PHP Fatal error: Class 'BaseMigration' not found in ...\app\database\migrations\2014_02_19_071702_create_users_table.php on line 6

Obviously it's having trouble autoloading it. How do I tell Laravel where to find it, or where should I move it to so that it can be found?

4
  • 2
    Just running composer dump-autoload seems to have done the trick actually. Commented Feb 19, 2014 at 7:49
  • @alexrussell: Yes.. if I do have a detailed answer that I'm confident is correct, then I'll usually answer my own question and accept it. Otherwise, I tend to post my findings as comments and let someone else claim the credit if they want to take the time to give a proper response :-) Antonio's answer below, for example, is much more detailed and informative than anything I would have come up with. Commented Feb 19, 2014 at 16:38
  • Fair enough. It's good to know an experienced member's protocol. I also usually tend not to answer these types of question for fear of looking like someone who's just out to get the rep for an answer already given. As you say though, there's no harm in providing the answer and some more detail for the rest of the community. Commented Feb 19, 2014 at 16:43
  • @alexrussell From my perspective, I'm just happy to get an answer. I don't need the extra points for answering my own question too. Then it looks like I'm just trying to get points, even though SO encourages it. That said, if no one does answer, I usually like to write something so that I can close it out. Sometimes there is no good answer though, so they just stay open forever... Commented Feb 19, 2014 at 17:46

1 Answer 1

2

Usually

composer dump-autoload

Fixes those kind of errors, but sometimes it doesn't.

To understand if the problem is not in Laravel, but in autoloading (Composer or even PHP), take a look a the files in

vendor/composer/*

If your file is not using PSR-0, PSR-4 nor file autoloading, it should be

vendor/composer/autoload_classmap.php

If your file class is listed there, the problem is in your code, you're referencing it wrongly. In those files you'll find also the way you have to reference to it, for instance, if you have a namespace set on it, you'll have to use it the way it appears on those files.

If it's not listed, the problem is in the guy responsible for autoloading things: Composer (maybe even PHP) and you can refresh it to try to fix it:

 rm -rf vendor
 rm composer.lock
 composer install
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.