That depends on how you are passing the new values through initially.
If you're posting to a route with the new values, you could set up a custom method to do something like
public function multiUpdate()
{
$newValues = Input::get('values');
foreach ($newValues as $key => $value) {
$tableData = Model::findOrFail($key);
$tableData['column'] = $value;
if (!$setting->save()) return Redirect::back()->withInput()->withErrors($setting->errors());
}
return Redirect::back()->with('Success', "Table was successfully updated!");
}
Yeah, thats horrible, because you are running a query for each update. 1000 users? 1000 queries. Not good.
This is a terrible solution and I'm still trying to find something better. I have to update ~10k rows and doing them like this is SLOW :(
This is from the official docs:
$affectedRows = User::where('votes', '>', 100)->update(array('status' => 2));
Sorry, didnt really read the question. This will not produce the CASE WHEN you're asking for. But it's still better than going through all records (inlcuding a select)
http://stackoverflow.com/questions/34885575/laravel-5-2-updati...
I have actually asked this exact question. If anyone has any idea how to do this it would be greatly appreciated.
why not just do a raw query? i know it's not the eloquent way but in your case this will give you better performance.
Sign in to participate in this thread!