Using Faker Slug in Laravel

 {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,
];
}

Comments

Popular posts from this blog

Running MyPhpAdmin on Linux

Laravel Working with Dates and Time