Friday, March 3, 2017

Laravel / Eloquent - How Do I get a Query Object When using DB::table()?

I have the following Eloquent logic:

$table_object = DB::table('users')->newQuery()
foreach($parameters as $key => $value){
    $table_object->where($key, '=', $value);
}
$table_object->get();

I am under the assumption that newQuery() will return an Eloquent object that I can chain where() off of.

This doesn't seem to work. Every time I run the above code, the raw query produced is missing the table name:

The error that gets outputted is:

No tables used (SQL: select *)



via Lloyd Banks

Advertisement