为Laravel中的所有记录设置列null

In table posts I have column rank. I need for all records (10000+) set column rank null. How I can do it?

I have static function:

 public static function calculateRank() {
      DB::statement("UPDATE posts set rank = null");
      DB::statement("UPDATE posts..."); //do calculate ranks for all posts
 }

I can do it with DB::statement. But how I can clear rank for all posts with eloquent, maybe will be better and faster?

I think it's very unlikely that eloquent would be quicker since it would execute the same SQL. It would be a bit nicer to read, though.

Update all posts using Eloquent:

Post::update(['rank' => null]);

If you want to set the rank based on some PHP logic, you might as well just loop over every element, but that would take more and more time as you have more posts. It might be better to calculate the rank each time a post is displayed (if that calculation is relatively quick).

You can do it simply using Laravel Eloquent as below:

Post::query()->update(['rank' => null]);