PHP code example of delgont / auth

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/ */

    

delgont / auth example snippets


<input id="username_email" type="text" class="form-control @error('username_email') is-invalid @enderror" name="username_email" value="{{ old('username_email') }}" 


..............
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']);

Route::get('/test', 'TestController@test')->middleware('role:admin');
Route::get('/test', 'TestController@test')->middleware('role:admin|hello');

Route::get('/momo', 'Momo@index')->name('momo')->middleware('permission:access_momo_dashboard');
 php artisan vendor:publish  --multiauth-config


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



return [
    'delimiter' => '|',

    'permissions' => [
      'manage_users',
      'access_momo_dashbaord'
    ]
];
`


composer
php artisan make:roleRegistrar Roles/ExampleRoleRegistrar
composer
php artisan role:sync