douyingzhan5905 2014-07-01 20:21
浏览 87
已采纳

Laravel 4.1,更改auth.model有效,但如果删除models / User.php文件则为L4 502s

The default Authentication model is app/models/User.php, set by the config item auth.model
That worked fine. So of course I decided to follow a nice guide a make my own namespaced directory to keep all of my models, repos, etc.

I added the line to composer.json to autoload, changed the auth.model setting to the path (model namespace is Models\User), but upon removing the models/user.php file, L4 kicks out a 502 with the (very brief) log entry of

...FatalErrorException' with message 'Class 'User' not found' in .../Illuminate/Database/Eloquent/Model.php:711

If I add back the models/User.php file, everything works, except it uses the wrong model to log in, so I have to keep a copy in each place.

Am I missing something, some other setting? I can't imagine the path to the User model is hard-coded, but it's sure acting that way.

This is with a fairly fresh Homestead install with Vagrant.

Update #1

Relevant lines from composer.json

"autoload": {
"classmap": [
"app/EC"  

Snippet of User class. They're the standard boilerplate User models, except I extend Eloquent with my ECBaseModel class, so the one in app/models extends \Models\ECBaseModel instead

<?php namespace Models;  
use \Illuminate\Auth\UserInterface;
use \Illuminate\Auth\Reminders\RemindableInterface;
class User extends ECBaseModel implements UserInterface, RemindableInterface
{
    getAuthIdentifier, getAuthPassword, getReminderEmail, getRememberTokens
}

Updated #2

[2014-07-01 20:04:09] homestead.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'User' not found' in /home/vagrant/Code/ec_api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:711
Stack trace:
#0 [internal function]: Illuminate\Exception\Handler->handleShutdown()
#1 {main} [] []

  • 写回答

1条回答 默认 最新

  • dongtang6681 2014-07-02 10:33
    关注

    Some people have suggested dump-autoload but that cannot be the case. PHP knows that it wants to talk to the User class and is failing to find it, but as it does not exist then running dump-autoload is not going to help. It would help only if PHP knew it wanted to talk to Models\User but could not find it, as the autoload lookup was old.

    Paste in the entire backtrace. The error will be in there. It will tell us what code is actually calling this old reference. When you see what is trying to call it, you can kill it.

    Update: PSR-4 is a little better at handling autoloading when it comes to namespaces.

    "autoload": {
        "psr-4": {
            "App\\": "app/src/"
        }
    },
    

    Then have app/src/Model/User.php and put it in the App\Model namespace, calling it User.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划