Adding Custom Guards: Closure Request Guards

Closure Request Guards

Use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

/**
 * Register any application authentication / authorization services.
 *
 * @return void
 */
public function boot()
{
    $this->registerPolicies();

    Auth::viaRequest('custom-token', function ($request) {
        return User::where('token', $request->token)->first();
    });
}

Related concepts

Adding Custom Guards: Closure Request Guards — Structure map

Clickable & Draggable!

Adding Custom Guards: Closure Request Guards — Related pages: