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.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题