hookable
hookable copied to clipboard
Fix Parameter Grouping with Laravel 7.x
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)
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.
Hi! This is an important fix, can you merge it, please?
@jarektkaczyk
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.
I too hope this can be merged ASAP. An application I'm having to support needs this to work in L7.
@jarektkaczyk plz help!
Any update on this?
@jarektkaczyk