Gideon Asare
Web Developer
Blog Post

Using Faker Slug in Laravel

12th August 2023 21:31:22

{use Illuminate\Support\Str;

use App\Models\Post;

class PostFactory extends Factory
{
protected $model = Post::class;
 
public function definition(): array
{
return [
'title' => $title = $this->faker->sentence(),
'slug' => Str::slug($title),
'content' => $this->faker->paragraph(),
'published_at' => null,
];
}