entrust icon indicating copy to clipboard operation
entrust copied to clipboard

Laravel 5.2 + multiauth use with custom provider

Open lankaen opened this issue 8 years ago • 2 comments

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 [email protected]

lankaen avatar Feb 15 '17 07:02 lankaen

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 avatar Jun 05 '18 12:06 PierreAlainKouakou

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

If it can help someone !

PierreAlainKouakou avatar Jun 05 '18 13:06 PierreAlainKouakou