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.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀