Giter VIP home page Giter VIP logo

Comments (9)

freshface avatar freshface commented on September 24, 2024 1

Hi

I am almost there

 $builder = ApiHandler::parseMultiple($query)->getBuilder();
        $queryBuilder = $builder->getQuery();
        $queryBuilder->where('project_content.name', 'like', 'Green%');

On thing I don't get is how you would use the except method.
Any tips?

from laravel-api-handler.

marcelgwerder avatar marcelgwerder commented on September 24, 2024

Nope, not yet. All you can do right now is adding the "custom" filter to the query builder yourself after the rest was applied. You can use the getBuilder method after calling parseSingle/parseMultiple to get started.

I'm thinking about a more powerful way to query the data for version 1.0 of the package.
The current approach of filtering is very limited because of the fact that the filter statements are divided in multiple get params and also due to the limitation of parameter key naming. I'm not yet past conceptual work though because of very limited time available for the project.

from laravel-api-handler.

freshface avatar freshface commented on September 24, 2024

Hi marcelgwerder

Thanks for the fast reply.
Would be nice to have in v1.0

Kinda new to laravel, is there an example available on how to add the custom filter?

from laravel-api-handler.

marcelgwerder avatar marcelgwerder commented on September 24, 2024

What you'll get with getBuilder is a query builder object and you'll thus have all the tools available described in the respective section of the Laravel docs: Database: Query Builder.

You may have to pass the get parameters to the api handler manually because it will otherwise try to add the custom filter to the query of the main table. There is a convenient except method on the request object. How you can pass the params manually is documented in the readme of the package.

from laravel-api-handler.

marcelgwerder avatar marcelgwerder commented on September 24, 2024

You can use the request object to access the get params:

public function index(Request $request) 
{
    // ...
    $builder = ApiHandler::parseMultiple($query, [], $request->except('project_content_name'))->getBuilder();
    if ($request->has('project_content_name')) {
        $queryBuilder = $builder->getQuery();
        $queryBuilder->where('project_content.name', 'like', $request->input('project_content_name').'%');
    }
    // ...
}

The getQuery call should actually not be necessary as far as I remember because the EloquentBuilder should pass all calls to the QueryBuilder automatically.

from laravel-api-handler.

freshface avatar freshface commented on September 24, 2024

Hi

When I do it like this http://nanopixel-dashboard.local:8888/api/projects?_config=meta-total-count,meta-filter-count&id=3&project_content_name=f

It still tries to access project.project_content_name:

{
    "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'project.project_content_name' in 'where clause' (SQL: select count(*) as aggregate from `project` left join `project_content` on `project_content`.`project_id` = `project`.`id` where `project`.`id` = 3 and `project_content`.`name` like %f% and `project`.`id` = 3 and `project`.`project_content_name` = f)",
    "code": "42S22",
    "status_code": 500
}

The $request->except('project_content_name') doesn't seem to be ignored.

 $builder = ApiHandler::parseMultiple($query, [], $request->except('project_content_name'))->getBuilder();
        //$queryBuilder = $builder->getQuery();

        if ($request->has('project_content_name')) {
            $builder->where('project_content.name', 'like', '%' . $request->input('project_content_name') . '%');
        }

from laravel-api-handler.

freshface avatar freshface commented on September 24, 2024

Never mind, I found the problem.
I had another ApiHandler::parseMultiple() which I overlooked.

from laravel-api-handler.

freshface avatar freshface commented on September 24, 2024

Another problem with this solution, the meta information gets lost when I do it like this, its an empty array.

 $builder = ApiHandler::parseMultiple($query, [], $request->except(['content_name', 'content_language']))->getBuilder();

        // This is a fix to search in other tables.
        if ($request->has('content_name')) {
            $builder->where('project_content.name', 'like', '%' . $request->input('content_name') . '%');
        }

         if ($request->has('content_language')) {
            $builder->where('project_content.language', '=', $request->input('content_language'));
        }

        return $builder->get();

from laravel-api-handler.

bemonio avatar bemonio commented on September 24, 2024

Hi!, sorry for reopen it. are there a method to solve the problem with meta information?

from laravel-api-handler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.