Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

Laravel 5.2 + multiauth use with custom provider #740

Open lankaen opened 7 years ago

lankaen commented 7 years ago

Hope this help someone

vendor/zizaco/entrust/src/commands/MigrationCommand.php Line 85 $provider= Config::get('entrust.provider'); $userModel = Config::get('auth.providers.'.$provider.'.model');

vendor/zizaco/entrust/src/Entrust/Middleware/EntrustRole.php Replace the code

use Closure; use Illuminate\Contracts\Auth\Guard; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Config;

class EntrustRole { protected $auth;

/**
 * Creates a new instance of the middleware.
 *
 * @param Guard $auth
 */
public function __construct(Guard $auth)
{
    $this->auth = $auth;
}

/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request $request
 * @param  Closure $next
 * @param  $roles
 * @return mixed
 */
public function handle($request, Closure $next, $roles)
{
   // dd( !Auth::guard('admin_backend')->check() );
    //if ($this->auth->guest() || !$request->user()->hasRole(explode('|', $roles))) {
    $provider= Config::get('entrust.provider');
    if ( !Auth::guard($provider)->check() || ! Auth::guard($provider)->user()->hasRole(explode('|', $roles)) ) {
        abort(403);
    }

    return $next($request);
}

}

config/entrust.php Add this to end // providers name from config/entrust.php
'provider' => 'users', 'user_table' => 'users',

database/migrations/ entrust_setup_tables.php change line 29

$table->foreign('user_id')->references('id')->on( Config::get('entrust.user_table')) //user_table

After that run -> php artisan migrate

You can easily use this with laravel multiauth

contact me any time sirisena9@gmail.com

PierreAlainKouakou commented 6 years ago

Thank guy !!!

But i get this error when i want to try run entrust migration [ReflectionException] Method Zizaco\Entrust\MigrationCommand::handle() does not exist

Help me !

PierreAlainKouakou commented 6 years ago

i solved it by changing fire method to handle in ( vendor-> zizaco-> entrust-> src-> commands-> MigrationCommand.php )

If it can help someone !