Login only if user is active using Laravel

前端 未结 19 1849
孤城傲影
孤城傲影 2020-11-30 23:26

I\'m currently working on my Laravel app and to prevent spam I decided that only active users are able to login. I\'m currently using Laravel\'s login system just like in La

19条回答
  •  臣服心动
    2020-11-30 23:52

    You can use Eloquent scopes: https://laravel.com/docs/5.5/eloquent#query-scopes

    like this:

    class User extends Authenticatable {
    ...
    /**
         * The "booting" method of the model.
         *
         * @return void
         */
        protected static function boot() {
            parent::boot();
    
            static::addGlobalScope('scopeActive', function (Builder $builder) {
                $builder->where('active', 1);
            });
        }
    ...
    

提交回复
热议问题