Coder Social home page Coder Social logo

bruno's People

Contributors

carghaez avatar esbenp avatar pmccarren avatar sureshamk avatar yeexel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bruno's Issues

Laravel 7 suport?

Hello, its possible to install this package in laravel version 7?
I'm trying to install it with composer and its not working :(.
Composer output:

Problem 1
- Conclusion: remove laravel/framework v7.18.0
- Conclusion: don't install laravel/framework v7.18.0
- optimus/bruno 3.0.0 requires laravel/framework ~5.4 -> satisfiable by laravel/framework[5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev].
- optimus/bruno 3.1.0 requires laravel/framework ~5.4 -> satisfiable by laravel/framework[5.4.x-dev, 5.5.x-dev, 5.6.x-dev, 5.7.x-dev, 5.8.x-dev].
- Can only install one of: laravel/framework[5.5.x-dev, v7.18.0].
- Can only install one of: laravel/framework[5.6.x-dev, v7.18.0].
- Can only install one of: laravel/framework[5.7.x-dev, v7.18.0].
- Can only install one of: laravel/framework[5.8.x-dev, v7.18.0].
- Can only install one of: laravel/framework[5.4.x-dev, v7.18.0].
- Installation request for laravel/framework (locked at v7.18.0, required as ^7.0) -> satisfiable by laravel/framework[v7.18.0].
- Installation request for optimus/bruno ~3.0 -> satisfiable by optimus/bruno[3.0.0, 3.1.0].

Installation failed, reverting ./composer.json to its original content.

Join of related models broken for BelongsTo

When joining related models with a BelongsTo relation, the following error is thrown:

Call to undefined method Illuminate\Database\Eloquent\Relations\BelongsTo::getQualifiedForeignKey()

Laravel 5.8 introduced the following breaking changes:

The getForeignKey, getQualifiedForeignKey, and getOwnerKey methods of the BelongsTo relationship have been renamed to getForeignKeyName, getQualifiedForeignKeyName, and getOwnerKeyName respectively, making the method names consistent with the other relationships offered by Laravel.

Wrong doc ?

Hi !

Thanks for this package, which is really useful :)
I just wanted to point out the fact that the doc seems pretty old: It says

composer require optimus/bruno ~1.0

when the latest release seems to be 2.0.5 (and 1.0 is not working with latest laravel version: 5.4)

Similarly, it says to call

use Optimus\Api\Controller\EloquentBuilderTrait;
use Optimus\Api\Controller\LaravelController;

when the namespace seems to have changed in favor of Optimus\Bruno.

That's it :)
Maybe I'm wrong and this point is not relevant, but just in case...

Have a nice day and thanks again !

What to do on shared children and pivot tables?

If a shared child already exists in the root object collection it will not be added again. How about shared children with pivot table data? Maybe save the pivot table data somewhere? Or should the pivot table data be whats left in the original collection?

array with attributes to fetch

Hi, really nice little package.

What about a new options to be specific of what are you fetching from the model. Maybe even when i am trying to get something from a relationship eager load that by default. Some feature like this can make querys in big tables easier to read and consume less bandwith.

Something like this...

get[
"id",
"description"
"role.name"
]

Reuse of custom filter within the same query will result in a join error

When using the same custom filter multiple times, the join statement will be appended twice to the query builder.

Example of the custom filter:

/**
     * @param Builder $query
     * @param         $method
     * @param         $clauseOperator
     * @param         $value
     *
     * @return Builder
     */
    public function filterStartLocation(Builder $query, $method, $clauseOperator, $value): Builder
    {
        // if clauseOperator is identical to false,
        // we are using a specific SQL method in its place (e.g. `in`, `between`)
        if ($clauseOperator === false) {
            $query->$method('locations.location_type_id', $value);
        } else {
            $query->$method('locations.location_type_id', $clauseOperator, $value);
        }

        return $query;
    }

As you can see, the custom filter will check the location_type within the location. the startLocation is an eloquent relation defined in the Model.

An error will occur when using this filter more then once within the same query:

The output of the Builder is:

Builder {#431 ▼
  #query: Builder {#417 ▼
    +connection: MySqlConnection {#128 ▶}
    +grammar: MySqlGrammar {#129 ▶}
    +processor: MySqlProcessor {#130}
    +bindings: array:7 [▶]
    +aggregate: null
    +columns: array:1 [▶]
    +distinct: false
    +from: "schedules"
    +joins: array:2 [▼
      0 => JoinClause {#877 ▼
        +type: "inner"
        +table: "locations"
        -parentQuery: Builder {#417}
        +connection: MySqlConnection {#128 ▶}
        +grammar: MySqlGrammar {#129 ▶}
        +processor: MySqlProcessor {#130}
        +bindings: array:7 [▶]
        +aggregate: null
        +columns: null
        +distinct: false
        +from: null
        +joins: null
        +wheres: array:1 [▼
          0 => array:5 [▼
            "type" => "Column"
            "first" => "schedules.end_location_id"
            "operator" => "="
            "second" => "locations.id"
            "boolean" => "and"
          ]
        ]
        +groups: null
        +havings: null
        +orders: null
        +limit: null
        +offset: null
        +unions: null
        +unionLimit: null
        +unionOffset: null
        +unionOrders: null
        +lock: null
        +operators: array:29 [▶]
        +useWritePdo: false
      }
      1 => JoinClause {#878 ▼
        +type: "inner"
        +table: "locations"
        -parentQuery: Builder {#417}
        +connection: MySqlConnection {#128 ▶}
        +grammar: MySqlGrammar {#129 ▶}
        +processor: MySqlProcessor {#130}
        +bindings: array:7 [▶]
        +aggregate: null
        +columns: null
        +distinct: false
        +from: null
        +joins: null
        +wheres: array:1 [▼
          0 => array:5 [▼
            "type" => "Column"
            "first" => "schedules.end_location_id"
            "operator" => "="
            "second" => "locations.id"
            "boolean" => "and"
          ]
        ]
        +groups: null
        +havings: null
        +orders: null
        +limit: null
        +offset: null
        +unions: null
        +unionLimit: null
        +unionOffset: null
        +unionOrders: null
        +lock: null
        +operators: array:29 [▶]
        +useWritePdo: false
      }
    ]
    +wheres: array:2 [▼
      0 => array:3 [▼
        "type" => "Nested"
        "query" => Builder {#886 ▼
          +connection: MySqlConnection {#128 ▶}
          +grammar: MySqlGrammar {#129 ▶}
          +processor: MySqlProcessor {#130}
          +bindings: array:7 [▶]
          +aggregate: null
          +columns: null
          +distinct: false
          +from: "schedules"
          +joins: null
          +wheres: array:1 [▼
            0 => array:5 [▼
              "type" => "Basic"
              "column" => "locations.location_type_id"
              "operator" => "="
              "value" => array:1 [▶]
              "boolean" => "and"
            ]
          ]
          +groups: null
          +havings: null
          +orders: null
          +limit: null
          +offset: null
          +unions: null
          +unionLimit: null
          +unionOffset: null
          +unionOrders: null
          +lock: null
          +operators: array:29 [▶]
          +useWritePdo: false
        }
        "boolean" => "and"
      ]
      1 => array:3 [▼
        "type" => "Nested"
        "query" => Builder {#871 ▼
          +connection: MySqlConnection {#128 ▶}
          +grammar: MySqlGrammar {#129 ▶}
          +processor: MySqlProcessor {#130}
          +bindings: array:7 [▶]
          +aggregate: null
          +columns: null
          +distinct: false
          +from: "schedules"
          +joins: null
          +wheres: array:1 [▼
            0 => array:5 [▼
              "type" => "Basic"
              "column" => "locations.location_type_id"
              "operator" => "="
              "value" => "8"
              "boolean" => "and"
            ]
          ]
          +groups: null
          +havings: null
          +orders: null
          +limit: null
          +offset: null
          +unions: null
          +unionLimit: null
          +unionOffset: null
          +unionOrders: null
          +lock: null
          +operators: array:29 [▶]
          +useWritePdo: false
        }
        "boolean" => "and"
      ]
    ]
    +groups: null
    +havings: null
    +orders: null
    +limit: null
    +offset: null
    +unions: null
    +unionLimit: null
    +unionOffset: null
    +unionOrders: null
    +lock: null
    +operators: array:29 [▶]
    +useWritePdo: false
  }
  #model: Schedule {#368 ▶}
  #eagerLoad: []
  #localMacros: []
  #onDelete: null
  #passthru: array:13 [▶]
  #scopes: []
  #removedScopes: []
}

Is there a workaround available for this issue?

--
Using Homestead with environment versions:

PHP:  7.2
Laravel: 5.6.39

Upgrade method names to match with laravel 5.4

In file vendor/optimus/bruno/src/EloquentBuilderTrait.php , there are couple of references of method getForeignKey() they are renamed in laravel 5.4 , replace it with getQualifiedForeignKeyName()

IN is not working

Hello,
Can you please help me with writing correct URL for filtering using IN operator.
A working example is highly appreciated.

Query for filtering

Hey, I can't get filtering work, it always says:

"message": "Filter group does not have the 'filters' key.",

This is the query i'm using.
api/v1/categories?filter_groups[filters][key]=name&filter_groups[filters][value]=tecnology&filter_groups[filters][operator]=eq

Hope you can help me.

Query Sort

Hey, I don't get it how do define the url for a sorting? The normal pattern isn't working. Can you give me an example? Thanks

Is there a way to get pagination metadata?

Hi there, first I'd like to say tanks and congrats for this great package.

I'm starting to use this package on my new project and i what to kow if there is a way to get the pagination meta-data?

Lets say I've requested /books?page=1&limit=10, how do i know about how many pages can i go through and what is the next page or if the next page exists, etc..

Sorry if I'm making a dump question, I just need a guide.

cannot get custom filtering to work

in ItemRepository I have a method:

    public function filterImages($query, $method, $clauseOperator, $value, $in)
    {
        if ($in) {
            call_user_func([$query, $method], 'product.categories', $value);
        } else {
            call_user_func([$query, $method], 'product.categories', $clauseOperator, $value);
        }
    }

when i filter for key "images" and value "image.jpg" this error always comes back:

"Argument 1 passed to Infrastructure\Database\Eloquent\Repository::filterImages() must be an instance of Optimus\Bruno\EloquentBuilderTrait, instance of Illuminate\Database\Eloquent\Builder given",

Filter_groups Example

Can anyone give an example of filter_groups please?
I don't know how to pass filter_group's options in url.
I use it like below, but does not work:
By clicking on the link, show questions that have answer with specified id.

<a class="btn btn-default" href="questions?Filter_groups=[{"or":false,"filters":[["answer", "eq",{{ $answer->id }}],]}]">Show Questions That Have This Answer</a><

In fact i want to pass this data :

[
    {
        "or": false,
        "filters": [
            ["answer", "eq", "id"],
        ]
    }
]

Use with SoftDelete Models

If you try to filter like so:

filter_groups: [
  {
    filters: [
      {
        key:'deleted_at', value:null, operator: 'eq', not: true
      }
    ]
  }
]

on a model with the softdelete trait, the resulting query will look something like this:

select * from users where (deleted_at is not null) and deleted_at is null

I couldnt come up with a better solution in my app than by extending Genie\Repository like so:

abstract class EloquentRepository extends Repository
{
    /**
     * Override abstract Repository class to modify query builder such that if soft delete key is provided
     * in request filters, the soft delete scope is correctly modified
     * @return Builder
     */
    protected function createBaseBuilder(array $options = [])
    {

        $query = $this->createQueryBuilder();

        $this->applyResourceOptions($query, $options);

        $model = $this->getModel();

        $traits = class_uses(get_class($model), true);
        if (in_array(SoftDeletes::class, $traits)) {
            $deletedAtKey = $model->getDeletedAtColumn();
            $filter_groups = array_get($options, 'filter_groups', []);
            foreach ($filter_groups as $filter_group) {
                $filters = array_get($filter_group, 'filters', []);
                foreach ($filters as $filter) {
                    $key = array_get($filter, 'key');
                    $negating = array_get($filter, 'not');

                    if ($key == $deletedAtKey && $negating) {
                        $query->withTrashed();
                    }
                }
            }
        }

        if (empty($options['sort'])) {
            $this->defaultSort($query, $options);
        }

        return $query;
    }
}

Use in ManyToMany realations

Can this package be used in n To n relations?
If i have this scenario :
Models
Answer
Question
AnswerQuestion

How to get All questions that have a specific answer?.

custom filter in nesting relationship

i found custom filter for direct relationship using relation name. but is it possible to filter value from nesting relationship. eg: Class A has relation to class B and again class B has relation to class C. if i want to use custom filter in class A to filter data from class C. is it possible to filter data?

Custom filters on BelongsToMany throws BadMethodCallException

"message": "Call to undefined method Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany::getQualifiedRelatedKeyName()", "exception": "BadMethodCallException", "file": "/var/www/bneapilocal/vendor/laravel/framework/src/Illuminate/Support/Traits/ForwardsCalls.php", "line": 50,

In EloquentBuilderTrait.php
In method joinRelatedModelIfExists
At line 299

Custom filters on BelongsToMany throws exception on the method call at line 299:
$relation->getQualifiedRelatedKeyName()
When I change it to:
$relation->getQualifiedRelatedPivotKeyName()

This works fine.

Breaking changes on Laravel 5.5.42

Hi @esbenp ,

I've seen that Laravel 5.5.42 has some breaking changes that cause filter failed to work on many-to-many relationship.

getQualifiedRelatedKeyName has been renamed to getQualifiedRelatedPivotKeyName

and

getQualifiedForeignKeyName has been renamed to getQualifiedForeignPivotKeyName

I've created a pull request for this.

PR #42

Feature: Optional shorthand filter syntax

I'd like to introduce a concept of 'Shorthand Filtering Syntax' (a.k.a. Shorthand).

What is Shorthand? Shorthand takes the a filter array[key, operator, value, not(optional)] and builds a verbose filter array upon evaluation.

For example, Shorthand Filtering would allow (Verbose):

$filter_groups = [
	[
		'or' => false,
		'filters' => [
			[
				'key' => 'user_id,
				'operator' => 'eq',
				'value' => 1
			],
			[
				'key' => 'type',
				'operator' => 'eq',
				'value' => 'moderator',
				'not' => true
			],
			[ 
				'key' => 'deleted_at',
				'operator' => 'eq',
				'value' => null
			]
		]
	]
];

... To be expressed in this manner (Shorthand):

$filter_groups = [
	[
		'or' => false,
		'filters' => [
			[ 'user_id, 'eq', 1 ],
			[ 'type', 'eq', 'moderator', true ],
			[ 'deleted_at', 'eq', null ]
		]
	]
];

Shorthand syntax is more concise while allowing greater readability, faster skimming. All of which are good things! :)

Usage of shorthand syntax is optional. The filter array should be treated as Shorthand IFF it does not contain the key 'key' and the number of array elements is >= 3.

I welcome and questions or comments!

second and third level filtering

Hello,

How can I do the second and third level for filtering with 2D and 3D array.
Aworking example will be highly appreciated.

e.g.
consider my array

"books":[
{
"id":1,
"author_id":1,
"title":"How to save the world from evil",
"pages":100,
"author":{
"id":1,
"name":"Optimus Prime"
"author_details":{
"id":1,
"dept":"Literature"
}
}
},

I want to search by books.author.name && books.author.author_details.dept
What should be changes in the controller?
How should be the API call?

Thanks

Required parameter $joins follows optional parameter $or

Description:
Uncaught ErrorException: Required parameter $joins follows optional parameter $or in /vendor/optimus/bruno/src/EloquentBuilderTrait.php:108

this line:
protected function applyFilter($queryBuilder, array $filter, $or = false, array &$joins)

when I delete "= false" it works.

throw InvalidArgumentException is trying to find an exception from the local namespace

See https://github.com/esbenp/laravel-controller/blob/master/src/EloquentBuilderTrait.php#L23

[2016-01-27 17:43:02] testing.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Call to undefined function Optimus\Api\Controller\InvalidArg
umentException() in /vagrant/Code/api/vendor/optimus/laravel-controller/src/EloquentBuilderTrait.php:23
Stack trace:
#0 /vagrant/Code/api/vendor/optimus/eloquent/src/Repository.php(176): Optimus\Database\Eloquent\Repository->applyResourceOptions(Object(Illuminate\Database\Eloquent\
Builder), Array)
#1 /vagrant/Code/api/vendor/optimus/eloquent/src/Repository.php(104): Optimus\Database\Eloquent\Repository->createBaseBuilder(Array)

Laravel syntax question with child relations for includes etc.

I'm trying to include the address in the company

It's fine on the singular model.

/api/v1/companies/22?includes%5B%5D=address

$resourceOptions = $this->parseResourceOptions();
$query = $this->project::query();
$this->applyResourceOptions($query, $resourceOptions);
$result = $query->find($id);

But I cant figure out how to change the syntax when calling a child.

/api/v1/projects/578/company?includes%5B%5D=address

$result = $this->project::find($id)->company;

Bug with not contains

Hello There,

I can't submit a pull request for this as i've changed so much of the code. However, I found a rather fatal bug when filtering by something that DOES NOT contain X

You current code ends up creating an SQL query that will look something like this :

select * from `users` where `users`.`customer_id` = 1 and `users`.`customer_id` is not null and (CAST(users.name AS CHAR) = NOTLIKE) order by `id` desc

Obviously this is wrong.

You simply need to make a small change to your case switch in the database trait from this :

$clauseOperator = ($not ? 'NOT':'') . (($dbType === 'postgres') ? 'ILIKE' : 'LIKE');

To this (adding a space after the NOT)

$clauseOperator = ($not ? 'NOT ':'') . (($dbType === 'postgres') ? 'ILIKE' : 'LIKE');

The end query will then look tike this :

select * from `users` where `users`.`customer_id` = 1 and `users`.`customer_id` is not null and (CAST(users.name AS CHAR) NOT LIKE '%frank%') order by `id` desc

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.