-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArticleFactory.php
36 lines (28 loc) · 1004 Bytes
/
ArticleFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Validator;
use App\Models\User;
class ArticleFactory extends Factory
{
protected static ?string $password;
public function definition(): array
{
$users = User::all();
$usersIds = $users->pluck('id')->toArray();
$data = [
'user_id' => $this->faker->randomElement($usersIds),
'title' => $this->faker->sentence(),
'description' => $this->faker->paragraph,
'category' => implode(', ', $this->faker->words()),
'created_at' => $this->faker->dateTimeBetween('-1 year')->format('Y-m-d')
];
Validator::make($data, [
'user_id' => 'required|integer|exists:users,id',
'title' => 'required|string|min:3|max:255',
'description' => 'required|string|min:10',
'category' => 'string|max:255',
]);
return $data;
}
}