Skip to content

Laravel 10.x #889

@jbrooksuk

Description

@jbrooksuk

I'm working on the cachethq/core, which uses the laravel-query-builder package and I'm running into an issue.

I have an index method in my controller that looks like so:

public function index()
{
    $components = QueryBuilder::for(Component::class)
        ->allowedIncludes(['group', 'incidents'])
        ->allowedFilters(['name', 'status', 'enabled'])
        ->allowedSorts(['name', 'order', 'id'])
        ->simplePaginate(request('per_page', 15));

    return ComponentResource::collection($components);
}

We also have a test, like so:

it('can list components', function () {
    Component::factory(2)->create();

    $response = getJson('/status/api/components');

    $response->assertOk();
    $response->assertJsonCount(2, 'data');
});

But, I get an exception when running the test:

Iluminate\Http\Request::get(): Argument #1 ($key) must be of type string, null given, called in /Users/james/Code/CachetHQ/core/vendor/spatie/laravel-query-builder/src/QueryBuilderRequest.php on line 164

Looking at QueryBuilderRequest.php

protected function getRequestData(?string $key = null, $default = null)
{
    if (config('query-builder.request_data_source') === 'body') {
        return $this->input($key, $default);
    }

    return $this->get($key, $default);
}

I don't think the use of $this->get() is the right use here, as this is comment lives in Request.php:

This method belongs to Symfony HttpFoundation and is not usually needed when using Laravel.

Instead, you may use the "input" method.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions