Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

facepalm!

I've been relying too much on logging queries. whereIn works. How do I mark this as solved?

The issue with the following code which repeats the 1st value of the array

Event::listen('illuminate.query', function($sql, $bindings, $time)
{
    foreach ($bindings as $i => $val) {
        $bindings[$i] = "'$val'";
    }

    $sql = str_replace(['?'], $bindings, $sql);

    Log::info($sql . ' elapsed time = ' . $time);
});

Using the following and the correct values were being used

$queries = DB::getQueryLog();
$last = end($queries);
Last updated 2 years ago.
0

You should use scopes instead of a static method.

public function scopeSimpleWhereIn_1( $query, $userArray )
{
	return $query->whereIn('id', $userArray )
		->get( array('id','email', 'first_name', 'last_name') );
}

Then call it like you did earlier:

$simple1 = User::simpleWhereIn_1( $userList );
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

DragonI dragoni Joined 31 Jan 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.