Is there a way to receive an instance of \Illuminate\Database\Eloquent\Builder
instead of \Illuminate\Database\Query\Builder
in the handleBuilder
method when creating a custom ArgBuilderDirective
?
See this example:
<?php
namespace Nuwave\Lighthouse\Schema\Directives;
use Nuwave\Lighthouse\Support\Contracts\ArgBuilderDirective;
use Nuwave\Lighthouse\Support\Contracts\DefinedDirective;
class EqDirective extends BaseDirective implements ArgBuilderDirective, DefinedDirective
{
/**
* Name of the directive.
*
* @return string
*/
public function name(): string
{
return 'eq';
}
/**
* Apply a "WHERE = $value" clause.
*
* @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
* @param mixed $value
* @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder
*/
public function handleBuilder($builder, $value)
{
// $builder is an instance of \Illuminate\Database\Query\Builder here.
// Is it possible to receive an instance of Illuminate\Database\Eloquent\Builder instead?
return $builder->where(
$this->directiveArgValue('key', $this->nodeName()),
$value
);
}
}