Update Entry Date by Code #6186
-
Hi there, I am looking for a way to randomize the Entry dates from a collection (a "blog" collection containing posts"). What I tried so far: foreach (Entry::whereCollection('blog')->all() as $entry) {
$entry->date = Carbon::today()->subDays(rand(0, 365));
$entry->save();
} and foreach (Entry::whereCollection('blog')->all() as $entry) {
$entry->set('date', Carbon::today()->subDays(rand(0, 365)));
$entry->save();
} But it seems, I cannot update the post date. Only the field 'date' is being updated, but not the filename containing the date. Can somebody please help me how to randomize the post dates? Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
duncanmcclean
Jun 10, 2022
Replies: 1 comment 2 replies
-
You can do |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
sewid
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do
$entry->date(Carbon::today()->subDays(rand(0, 365))))