Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

caneara/tipsea

13 stars
1 code files
View caneara/tipsea on GitHub

database/factories/TipFactory.php

Open in GitHub
use App\Models\Tip;
use App\Models\User;
use App\Models\Banner;
use App\Types\Factory;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
 
class TipFactory extends Factory
{
public static array $tags = [
'PHP', 'Python', 'JavaScript', 'C#', 'Laravel',
'Node', 'Vue', 'React', 'MySQL', 'Postgres',
'Visual Basic', 'F#', 'Svelte', 'Angular',
];
 
public function configure() : static
{
return $this->afterCreating(function(Tip $tip) {
return tap($tip)->update(['slug' => "{$tip->id}-{$tip->slug}"]);
});
}
 
public function definition() : array
{
return [
'user_id' => User::factory(),
'banner_id' => Banner::factory(),
'title' => $title = fake()->text(50),
'slug' => Str::slug($title),
'summary' => fake()->text(150),
'teaser' => fake()->text(500),
'theme' => fake()->randomElement(['light', 'dark']),
'gradient' => fake()->numberBetween(1, 12),
'card' => uuid(),
'first_tag' => ($tags = Arr::random(static::$tags, 4))[0],
'second_tag' => $tags[1],
'third_tag' => $tags[2],
'fourth_tag' => $tags[3],
'content' => $this->generateContent(),
'attribution' => fake()->boolean() ? 'https://' . fake()->domainName() : null,
'shared' => true,
'published_at' => now()->subDays(rand(1, 100)),
];
}
 
protected function generateContent() : string
{
return Str::of(fake()->text(200))
->append("\n\n```js\n")
->append("let value = '" . Str::random(20) . "';")
->append("\n```\n\n")
->append(fake()->text(200))
->toString();
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.