1. Go to this page and download the library: Download delgont/auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
..............
Schema::table('users', function (Blueprint $table) {
$table->nullableMorphs('user');
});
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Delgont\Cms\Notifications\Auth\ResetPassword as ResetPasswordNotification;
use Delgont\Auth\Concerns\HasUserTypes;
class User extends Authenticatable
{
use Notifiable, HasUserTypes, ModelHasPermissions, ModelHasSingleRole;
namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
public function user()
{
return $this->morphOne('App\User', 'user');
}
}
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Delgont\Auth\Concerns\ModelHasRoles;
class User extends Authenticatable
{
/*
| Use Delgont\Auth\Concerns\ModelHasRoles trait
|
*/
use ModelHasRoles;
}
# Giving role using role names
$model->assignRole(['admin','accountant']);
auth()->user()->assignRole(['admin','accountant']);
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Delgont\Auth\Concerns\MultiAuthCredentials;
use Illuminate\Http\Request;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller - Multi Authentication using email or username
|--------------------------------------------------------------------------
| Use Delgont\Auth\Concerns\MultiAuthCredentials trait
| You must override the credentials and username functions as shown below
|
*/
use AuthenticatesUsers, MultiAuthCredentials;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function credentials(Request $request)
{
return $this->multiAuthCredentials($request);
}
public function username()
{
return 'username_email';
}
}