DB ::update('UPDATE projects DESC, (select @cnt:=0) as cnt SET rank=(@cnt:=@cnt+1) ORDER BY lift_at');
DB ::update('UPDATE projects, (select @cnt:=0) as cnt SET rank=(@cnt:=@cnt+1), ORDER BY lift_at DESC');
DB ::update('UPDATE projects, (select @cnt:=0) as cnt SET rank=(@cnt:=@cnt+1) ORDER BY lift_at DESC');
General error: 1221 Incorrect usage of UPDATE and ORDER BY
DB ::update('UPDATE projects, ORDER BY lift_at DESC, (select @cnt:=0) as cnt SET rank=(@cnt:=@cnt+1)');
$projects=Project::orderBy('lift_at', 'desc')
->get()
->map(function ($item, $index) {
$item['rank'] = $index + 1;
return $item;
});
foreach ($projects as $project)
{
// dd($project);
$project->update(['rank']);
}
DB::statement('CREATE TEMPORARY TABLE projects_temp LIKE projects');
DB::statement('INSERT projects_temp SELECT * FROM projects');