hookable icon indicating copy to clipboard operation
hookable copied to clipboard

Fix Parameter Grouping with Laravel 7.x

Open EK1771 opened this issue 5 years ago • 9 comments

Laravel 7.x introduced the following change https://github.com/laravel/framework/pull/30934 allowing for the feature https://laravel.com/docs/7.x/queries#subquery-where-clauses

This currently breaks parameter grouping when using eloquence due to the where() function passing = as the default operator even if a closure is passed.

This MR aims to fix the issue by detecting if a closure is passed and if so, not applying the default = operator.

To replicate the bug using sample Code on a fresh Laravel 7 install with sofa/eloquence-base:

app/User.php

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Sofa\Eloquence\Eloquence;

class User extends Authenticatable
{
    use Notifiable, Eloquence;

    protected $fillable = [
        'name', 'email', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];

    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

routes/web.php

Route::get('/', function () {

    App\User::where(function ($query) {
        $query->whereNull('remember_token')
              ->orWhere('email','!=','[email protected]');
    })->get();

});

Results in the error

Illuminate\Database\QueryException
SQLSTATE[HY000]: General error: 1096 No tables used (SQL: select * from `users` where (select * where `remember_token` is null or `email` != [email protected]) is null)

EK1771 avatar Apr 19 '20 03:04 EK1771

Is it possible to merge this request? It would solve a problem with advanced where statements when using Laravel 7.x and your eloquence package. I've tried this fix and it works.

bytebrain avatar Dec 08 '20 16:12 bytebrain

Hi! This is an important fix, can you merge it, please?

gabomasi avatar Jan 05 '21 20:01 gabomasi

@jarektkaczyk

gabomasi avatar Jan 05 '21 20:01 gabomasi

I also really need this fix. My entire application is broken after upgrading to L7. Could this please be merged? It's been almost a year... I've also tested this in combination with Mappable and it works well.

rubenlagatie avatar Mar 11 '21 09:03 rubenlagatie

I too hope this can be merged ASAP. An application I'm having to support needs this to work in L7.

glennjacobs avatar Jun 09 '21 15:06 glennjacobs

@jarektkaczyk plz help!

gfernandez-me avatar Jul 25 '21 17:07 gfernandez-me

Any update on this?

roelVerdonschot avatar Sep 28 '21 08:09 roelVerdonschot

@jarektkaczyk

paulosscruz avatar Oct 26 '21 04:10 paulosscruz

I used composer patches to apply this fix to my project,

  1. An example of using composer patches - link
  2. Install composer-patches - link to apply the patches.

maqduni avatar Apr 03 '23 04:04 maqduni