douyinjiao9351 2014-02-19 07:38
浏览 77
已采纳

Laravel类包括路径

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?

  • 写回答

1条回答 默认 最新

  • dongmeiba6151 2014-02-19 12:54
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看