selahattinunlu / laravel-api-query-builder

Laravel & Lumen Api Query Builder Package
332 stars 66 forks source link

Adding additional 'where' clause #28

Closed benrolfe closed 6 years ago

benrolfe commented 7 years ago

I'd like to apply an extra 'where' clause to every request.

ie: For an incoming API request I want to limit the results to only return results that are "owned" by the requesting user. I need to add an additional where clause for "organisation_id", which cannot be overridden through the URL's GET parameters.

Without success, I've already tried$request->query->add(['organisation_id' => 5]); and $_GET['organisation_id'] = 5.

Any suggestions?

rtyshyk commented 6 years ago

You can do it like this

    public function index(Request $request)
    {
        $query = $request->query();

        if (array_key_exists('version', $query) === false) {
            $query['version'] = \App\System::getVersion();
        }

        $request = RequestCreator::createWithParameters($query);

        return (new QueryBuilder(new Code(), $request))->build()->paginate();
    }
benrolfe commented 6 years ago

I then get this error: "ErrorException Undefined index: PATH_INFO".

Can anyone help?

rtyshyk commented 6 years ago

@benrolfe If you use nginx check your fastcgi_params, you must have there next line fastcgi_param PATH_INFO $fastcgi_path_info; If you use some other web server, check the documentation for your web server