I have raw query:
INSERT INTO employee (fk_country_id, employee_id, fk_city_id, password, role, email, joined_at, resigned_at, created_at, updated_at) VALUES (?, ?, (SELECT id FROM city WHERE city.id = ?), ?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE email = VALUES(email), joined_at = VALUES(joined_at), resigned_at = VALUES(resigned_at)
I am executing the query like this:
DB::insert($query, $parameters);
where the values of the parameters are in the form of array.
Since there are huge amount of rows for the INSERT and UPDATE opertion, I need to optimize the query to insert values of multiple rows in a single query.
How can I optimize my query with the help of Laravel?
There are some options which allows to run queries with nested arrays but I wasn't able to get that working with:
DB::insert();
I want to avoid the use of "(?, ?, ?), (?, ?, ?)...." during INSERT operation. How can Laravel facilitate this sort of thing to make the code look cleaner and optimized?
$data = ['column' => 'value, ...], ..]
and useModel::insert($data)
– Timework