【发布时间】:2015-05-18 19:31:45
【问题描述】:
这是我目前拥有的:
$sortOrder = ['0','1','4','2','3'];
$cards = ComboCard::where('username', '=', $user->username)
->where('combo_uid', '=', $comboUid)
->select('id', 'card_order')
->orderBy('card_order', 'ASC')
->get();
for($i=0; $i<count($cards); $i++) { // currently hits the database n times based on count($cards)
$index = $sortOrder[$i];
$cards[$index]->card_order = $i;
$cards[$index]->save();
}
【问题讨论】:
标签: php mysql laravel eloquent fluent