src/Schema/Directives/CanDirective.php
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $previousResolver = $value->getResolver();

        return $next(
            $value->setResolver(
                function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($previousResolver) {
                    $gate = app(Gate::class);
                    $gateArguments = $this->getGateArguments();

                    if ($id = $args['id'] ?? null) {
                        /** @var \Illuminate\Database\Eloquent\Model $modelClass */
                        $modelClass = $this->getModelClass();

                        $gateArguments[0] = $modelClass::findOrFail($id);
                    }

                    $this->getAbilities()->each(
                        function (string $ability) use ($context, $gate, $gateArguments): void {
                            $this->authorize($context->user(), $gate, $ability, $gateArguments);
                        }
                    );

                    return call_user_func_array($previousResolver, func_get_args());
                }
            )
        );
    }
public function handleField(FieldValue $value, Closure $next): FieldValue
    {
        $previousResolver = $value->getResolver();

        return $next(
            $value->setResolver(
                function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($previousResolver) {
                    $gate = app(Gate::class);
                    $gateArguments = $this->getGateArguments();

                    if ($id = $args['id'] ?? null) {
                        /** @var \Illuminate\Database\Eloquent\Model $modelClass */
                        $modelClass = $this->getModelClass();

                        $gateArguments[0] = $modelClass::findOrFail($id);
                    }

                    $this->getAbilities()->each(
                        function (string $ability) use ($context, $gate, $gateArguments): void {
                            $this->authorize($context->user(), $gate, $ability, $gateArguments);
                        }
                    );

                    return call_user_func_array($previousResolver, func_get_args());
                }
            )
        );
    }
public function handleField ( FieldValue $ value , Closure $ next ) : FieldValue { $ previousResolver = $ value -> getResolver ( ) ; return $ next ( $ value -> setResolver ( function ( $ root , array $ args , GraphQLContext $ context , ResolveInfo $ resolveInfo ) use ( $ previousResolver ) { $ gate = app ( Gate :: class ) ; $ gateArguments = $ this -> getGateArguments ( ) ; if ( $ id = $ args [ 'id' ] ?? null ) { /** @var \Illuminate\Database\Eloquent\Model $modelClass */ $ modelClass = $ this -> getModelClass ( ) ; $ gateArguments [ 0 ] = $ modelClass :: findOrFail ( $ id ) ; } $ this -> getAbilities ( ) -> each ( function ( string $ ability ) use ( $ context , $ gate , $ gateArguments ) : void { $ this -> authorize ( $ context -> user ( ) , $ gate , $ ability , $ gateArguments ) ; } ) ; return call_user_func_array ( $ previousResolver , func_get_args ( ) ) ; } ) ) ; }
Ensure the user is authorized to access this field.

@param  \Nuwave\Lighthouse\Schema\Values\FieldValue  $value
@param  \Closure  $next
@return \Nuwave\Lighthouse\Schema\Values\FieldValue
Ensure the user is authorized to access this field .