Support the ongoing development of →
posted 10 years ago
Last updated 1 year ago.


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 1 year ago.

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 1 year ago.

Sign in to participate in this thread!


Your banner here too?

DragonI dragoni Joined 31 Jan 2014


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

Your logo here?

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

© 2024 - All rights reserved.