Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php how to check if user has a role on login

// in users Model
public function hasRole($role)
    {
        if ($this->roles()->where('name', $role)->first()) {
            return true;
        }
        // else
        return false;
    }

// In login controller
// first comment out default laravel home redirect

// protected $redirectTo = RouteServiceProvider::HOME;

// then, redirect user(s) based on their role
    protected function authenticated(Request $request, $user)
    {
        if ($user->hasRole('administrator')) {
            return redirect()->route('users.admin.index');
        }

        if ($user->hasRole('user')) {
            return redirect()->route('home');
        }
    }
Comment

PREVIOUS NEXT
Code Example
Php :: Eloquent orWhere clousure 
Php :: laravele primrary key 
Php :: download file from s3 using laravel 
Php :: search line phpstorm mac 
Php :: Remove the additional notes area from the WooCommerce checkout 
Php :: php get non unique values from array 
Php :: php enc 
Php :: menyimpan get di laravel 
Php :: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:xampphtdocsJob Verificationlogin esult.php on line 38 
Php :: laravel create multiple request 
Php :: wordpress page template comment 
Php :: how to add accept and decline button in php form 
Php :: File Open File Read File Close 
Php :: discord.py Levels 
Php :: php json decode from url image 
Php :: spatie/laravel-health 
Php :: wp php get total product order quantity 
Php :: acho in php 
Php :: php artisan seading 
Php :: laravel how to fetch user from user model based on id from post 
Php :: simple php round When a parameter is passed with a specific precision value 
Php :: Create mocking dependency in unit test Laravel 
Php :: laravel handle image validation 
Php :: wordpress redirect attachment page to file 
Php :: convert any date to db date in suitecrm 
Php :: Natural numbers from php 
Php :: returning two yajra datatable using single method on the sam view laravel 
Php :: symfony server:start not working 
Php :: calculate age from date of birth php 
Php :: count same datetimes in foreach and group them php 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =