Level 13
Could try DB::statement($query);
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Here is the withoutColumn() function in the WarehouseProduct model:
/**
* Get all columns of model
*
* @return Array
*/
public static function getTableColumns() {
$model = new Product();
return $model->getConnection()
->getSchemaBuilder()
->getColumnListing($model->getTable());
}
/**
* Return model's columns without given columns
*
* @param Array $without_columns
* @return Array
*/
public static function withoutColumn(Array $without_columns) {
return array_diff(self::getTableColumns(), $without_columns);
}
I have this SQL query what I want to run:
$query = 'INSERT INTO warehouse_product_backups (SELECT ' .
implode(',', WarehouseProduct::withoutColumn(['id'])) .
' FROM warehouse_products)'
As you see here isn't any parameters, I just want to copy datas from one table into another (without id column).
Now I want to do something like this:
DB::insert($query);
Or:
DB::run($query);
This last one said FatalThrowableError: Call to protected method Illuminate\Database\Connection::run() from context 'Illuminate\Database\DatabaseManager'
Any idea?
Could try DB::statement($query);
Please or to participate in this conversation.