framework icon indicating copy to clipboard operation
framework copied to clipboard

[4.3] Auth driver 'eloquent' not working

Open rspahni opened this issue 12 years ago • 10 comments

Illuminate\Database\Eloquent\Model throws an exception "Call to a member function connection() on a non-object" on line 2840. My database connection is set up correctly. With driver 'database', Auth is working just fine.

    /**
     * Resolve a connection instance.
     *
     * @param  string  $connection
     * @return \Illuminate\Database\Connection
     */
    public static function resolveConnection($connection = null)
    {
        return static::$resolver->connection($connection);
    }

rspahni avatar Aug 27 '14 16:08 rspahni

Getting this also. Looks like boot() on DatabaseServiceProvider class is not getting called?

mfsousa avatar Aug 28 '14 01:08 mfsousa

hummm, I guess I have some code on my AppServiceProvider that is using db, if on providers array from config/app.php, I place Illuminate\Database\DatabaseServiceProvider first, it will fix the error.

mfsousa avatar Aug 28 '14 01:08 mfsousa

As 4.3 is WIP, too early to report issues.

rspahni avatar Aug 31 '14 10:08 rspahni

Not at all, if there is a bug, it should be fixed.

GrahamCampbell avatar Aug 31 '14 10:08 GrahamCampbell

Pretty sure you're going something with $app ['db'] in register() method when you should be using boot() method.

crynobone avatar Aug 31 '14 11:08 crynobone

@crynobone, no such thing anywhere throughout my app.

rspahni avatar Aug 31 '14 11:08 rspahni

Is this replicable on a fresh installation of 4.3 (not upgrading existing app)?

crynobone avatar Aug 31 '14 11:08 crynobone

My app is actually built on a fresh installation. But fair point nonetheless. Will try to replicate this issue on a separate fresh 4.3 and report back.

rspahni avatar Aug 31 '14 11:08 rspahni

I have: View::share('currentUser', Auth::user());

On boot() from AppServiceProvider.

It will work fine if no authentication was made, but just after I authenticate, I will get that error.

If I comment that line the error disappears.

Not sure if I should add that line there... Before I was adding on a setupLayout() of BaseController but that stop working for some reason on 4.3.

Do you tested with something like that? How I should do that?

mfsousa avatar Aug 31 '14 12:08 mfsousa

Actually, @mfsousa and @crynobone, you both pointed me in the right direction: In fact I had included in AppServiceProvider's boot section a custom facade method that would involve db access via the Session facade when logged in, which I hadn't realized until following the call stack with xdebug. Now, per @mfsousa's point, I could move AppServiceProvider down the list of service providers in config.app. However, I'll rather admit I misunderstood the purpose of AppServiceProvider to begin with and should bootstrap my stuff differently. Either way, not a Laravel issue for sure and thus closed. Thank you sirs for your help!

rspahni avatar Aug 31 '14 16:08 rspahni