Skip to content

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

Merged
taylorotwell merged 4 commits into
laravel:5.8from
epalmans:5.8
Mar 3, 2019
Merged

[5.8] Method on EloquentUserProvider to create query builder instance#27734
taylorotwell merged 4 commits into
laravel:5.8from
epalmans:5.8

Conversation

@epalmans

@epalmans epalmans commented Mar 1, 2019

Copy link
Copy Markdown
Contributor

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');
    }
}

Comment thread src/Illuminate/Auth/EloquentUserProvider.php
@epalmans

epalmans commented Mar 2, 2019

Copy link
Copy Markdown
Contributor Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants