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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog