Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Method on EloquentUserProvider to create query builder instance #27734

Merged
merged 4 commits into from Mar 3, 2019

Conversation

Projects
None yet
3 participants
@epalmans
Copy link

epalmans commented Mar 1, 2019

Reason: allows easy extension for a custom eloquent based auth provider in case, for example, you'd only need to have an extra constraint on the backing model applied. Prevents the need to fully implement the UserProvider interface.

Explanation of changes in EloquentUserProvider: instead of calling newQuery() on the model instance directly, now done through a protected method that can easily be overriden.

Example implementation where someone would have an "admin" guard that should only validate when a extra criteria (a field on the users table) is set:

<?php

namespace App\Extensions;

use Illuminate\Auth\EloquentUserProvider;

class MyEloquentAdminProvider extends EloquentUserProvider
{
    protected function modelQuery($model = null)
    {
        return parent::modelQuery($model)->where('role', 'admin');
    }
}
@epalmans

This comment has been minimized.

Copy link
Author

epalmans commented Mar 2, 2019

note to maintainers: new commit 391eae8 adds back in a newQuery call (through the new modelQuery method) that was taken out at f74c83e

@GrahamCampbell GrahamCampbell changed the title Method on EloquentUserProvider to create query builder instance [5.8] Method on EloquentUserProvider to create query builder instance Mar 2, 2019

@taylorotwell taylorotwell merged commit b896cce into laravel:5.8 Mar 3, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.