Replies: 2 comments
-
Hey, calling $builder->dd();
// calls:
// src/Illuminate/Database/Eloquent/Builder (2114)
public function __call($method, $parameters)
{
// ...
if (in_array(strtolower($method), $this->passthru)) {
return $this->toBase()->{$method}(...$parameters);
}
// ...
}
// which calls...
// src/Illuminate/Database/Eloquent/Builder (1910)
public function toBase()
{
return $this->applyScopes()->getQuery();
}
// which calls...
// src/Illuminate/Database/Eloquent/Builder (1458)
public function applyScopes()
{
// ...
$scope->apply($builder, $this->getModel());
// ...
return $builder;
}
// which calls...
// app/Scopes/MemoryScope.php (13)
public function apply(Builder $builder, Model $model): void
{
$builder->dd();
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
A suitable workaround for the example provided would be: use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class MemoryScope implements Scope
{
public function apply(Builder $builder, Model $model): void
{
//
}
}
class User extends Model
{
protected static function boot() {
parent::boot();
static::addGlobalScope(new MemoryScope);
}
}
Route::get('/', function (){
User::query()->dd();
return view('playground', [
'title' => 'Laravel Playground'
]);
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel Version
12.x
PHP Version
8.3
Database Driver & Version
No response
Description
A bit hard to say, I may be dumb on this one.
A strange memory issue occurs when I use ->dd() function inside scope to builder. I wish to check how sql currently looks, it has builder instance passed but when using ->dd function it goes to memory issue which seems not right.
I thought, it was due to some buggy code I have written. But I tested in laravel playground in online too and same issue. Below I have provided snippet.
Steps To Reproduce
`<?php
// paste straight to laravel playground.
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class MemoryScope implements \Illuminate\Database\Eloquent\Scope
{
public function apply(Builder $builder, Model $model): void
{
$builder->dd();
}
}
class User extends \Illuminate\Database\Eloquent\Model
{
protected static function boot() {
parent::boot();
static::addGlobalScope(new MemoryScope);
}
}
Route::get('/', function (){
User::query()->get();
return view('playground', [
'title' => 'Laravel Playground'
]);
});
`
Beta Was this translation helpful? Give feedback.
All reactions