Skip to content

Commit

Permalink
Merge pull request #403 from awcodes/feat/add-random-timestamps-to-fa…
Browse files Browse the repository at this point in the history
…ctory

Feat: add randmon timestamps to media factory
  • Loading branch information
awcodes authored Jan 2, 2024
2 parents 3cd719f + 3aba602 commit acb42a6
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions database/factories/MediaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,34 @@ class MediaFactory extends Factory
public function definition(): array
{
$fileName = collect([
'alberto-restifo-Ni4NgA64TFQ-unsplash',
'blake-verdoorn-cssvEZacHvQ-unsplash',
'daniel-roe-lpjb_UMOyx8-unsplash',
'dave-hoefler-lsoogGC_5dg-unsplash',
'david-marcu-78A265wPiO4-unsplash',
'dawid-zawila--G3rw6Y02D0-unsplash',
'eberhard-grossgasteiger-pBgnT4KH8d4-unsplash',
'eberhard-grossgasteiger-y2azHvupCVo-unsplash',
'fabian-quintero-UWQP2mh5YJI-unsplash',
'federico-respini-sYffw0LNr7s-unsplash',
'felix-mittermeier-L4-16dmZ-1c-unsplash',
'guillaume-briard-QegnXyECDfw-unsplash',
'henry-be-IicyiaPYGGI-unsplash',
'igor-kasalovic-tNDvFkxkBHo-unsplash',
'joel-vodell-TApAkERW5pQ-unsplash',
'kees-streefkerk-Adl90-aXYwA-unsplash',
'luca-bravo-zAjdgNXsMeg-unsplash',
'lukasz-szmigiel-jFCViYFYcus-unsplash',
'niko-photos-tGTVxeOr_Rs-unsplash',
'robert-lukeman-_RBcxo9AU-U-unsplash',
'robert-lukeman-zNN6ubHmruI-unsplash',
'tim-swaan-eOpewngf68w-unsplash',
])->random() . '.jpg';
'alberto-restifo-Ni4NgA64TFQ-unsplash',
'blake-verdoorn-cssvEZacHvQ-unsplash',
'daniel-roe-lpjb_UMOyx8-unsplash',
'dave-hoefler-lsoogGC_5dg-unsplash',
'david-marcu-78A265wPiO4-unsplash',
'dawid-zawila--G3rw6Y02D0-unsplash',
'eberhard-grossgasteiger-pBgnT4KH8d4-unsplash',
'eberhard-grossgasteiger-y2azHvupCVo-unsplash',
'fabian-quintero-UWQP2mh5YJI-unsplash',
'federico-respini-sYffw0LNr7s-unsplash',
'felix-mittermeier-L4-16dmZ-1c-unsplash',
'guillaume-briard-QegnXyECDfw-unsplash',
'henry-be-IicyiaPYGGI-unsplash',
'igor-kasalovic-tNDvFkxkBHo-unsplash',
'joel-vodell-TApAkERW5pQ-unsplash',
'kees-streefkerk-Adl90-aXYwA-unsplash',
'luca-bravo-zAjdgNXsMeg-unsplash',
'lukasz-szmigiel-jFCViYFYcus-unsplash',
'niko-photos-tGTVxeOr_Rs-unsplash',
'robert-lukeman-_RBcxo9AU-U-unsplash',
'robert-lukeman-zNN6ubHmruI-unsplash',
'tim-swaan-eOpewngf68w-unsplash',
])->random() . '.jpg';

$directory = config('curator.directory');
$disk = config('curator.disk');

if (! Storage::disk($disk)->exists($directory . '/' . $fileName)) {
if (!Storage::disk($disk)->exists($directory . '/' . $fileName)) {
$fileContents = file_get_contents('https://res.cloudinary.com/aw-codes/image/upload/curator/seed-data/' . $fileName);
Storage::disk($disk)->put($directory . '/' . $fileName, $fileContents);
}
Expand Down Expand Up @@ -74,4 +74,16 @@ public function private(): MediaFactory
];
});
}

public function randomTimestamps(): MediaFactory
{
return $this->state(function (array $attributes) {
return [
'created_at' => \Carbon\Carbon::now()->addDays(rand(-800, 0))->addMinutes(rand(0,
60 * 23))->addSeconds(rand(0, 60)),
'updated_at' => \Carbon\Carbon::now()->addDays(rand(-799, 0))->addMinutes(rand(0,
60 * 23))->addSeconds(rand(0, 60))
];
});
}
}

0 comments on commit acb42a6

Please sign in to comment.