Quantcast
Channel: Login only if user is active using Laravel - Stack Overflow
Viewing all articles
Browse latest Browse all 25

Answer by Healyhatman for Login only if user is active using Laravel

$
0
0

I needed mine to be combined with the Eloquent provider since we are not using the standard User model / table.

In auth.php

'providers' => ['custom' => ['driver' => 'active-user-provider','model' => App\CustomModel::class,        ]    ]'guards' => ['web' => ['driver' => 'session','provider' => 'custom'      ]],'passwords' => ['custom' => ['provider' => 'custom',        ....    ]]

In App\Extensions\ActiveUserProvider

class ActiveUserProvider extends EloquentUserProvider{    /**     * Get a new query builder for the model instance.     *     * @param \Illuminate\Database\Eloquent\Model|null $model     * @return \Illuminate\Database\Eloquent\Builder     */    protected function newModelQuery($model = null)    {        return parent::newModelQuery($model)            ->where('active', true);    }}

In AuthServiceProvider

Auth::provider('active-user-provider', fn($app, array $config) =>    new ActiveUserProvider($app['hash'], $config['model']));

This way it also only sends password reset emails to active workers.


Viewing all articles
Browse latest Browse all 25

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>