1 | <?php
|
---|
2 |
|
---|
3 | namespace Database\Factories;
|
---|
4 |
|
---|
5 | use App\Models\Department;
|
---|
6 | use App\Models\Folder;
|
---|
7 | use Carbon\Carbon;
|
---|
8 | use Faker\Provider\DateTime;
|
---|
9 | use Illuminate\Database\Eloquent\Factories\Factory;
|
---|
10 | use Illuminate\Support\Arr;
|
---|
11 | use Illuminate\Support\Facades\Storage;
|
---|
12 |
|
---|
13 | class FolderFactory extends Factory
|
---|
14 | {
|
---|
15 | /**
|
---|
16 | * The name of the factory's corresponding model.
|
---|
17 | *
|
---|
18 | * @var string
|
---|
19 | */
|
---|
20 | protected $model = Folder::class;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Define the model's default state.
|
---|
24 | *
|
---|
25 | * @return array
|
---|
26 | */
|
---|
27 | public function definition()
|
---|
28 | {
|
---|
29 | //$inputArray = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95];
|
---|
30 | //$deptId = Arr::random($inputArray);
|
---|
31 |
|
---|
32 | $deptId = $this->faker->numberBetween(1, 10);
|
---|
33 |
|
---|
34 | $deptCode = Department::find($deptId)->code;
|
---|
35 |
|
---|
36 | $name = $this->faker->unique()->firstName();
|
---|
37 |
|
---|
38 | $location = 'Departments' . DIRECTORY_SEPARATOR . $deptCode . DIRECTORY_SEPARATOR . $name;
|
---|
39 | Storage::disk('local')->makeDirectory($location);
|
---|
40 |
|
---|
41 | return [
|
---|
42 | 'arch_id' => $deptCode . "/" . $this->faker->unique()->randomNumber(),
|
---|
43 | 'name' => $name,
|
---|
44 | 'note' => "This a note field",
|
---|
45 | 'location' => $location,
|
---|
46 | 'user_id' => 1,
|
---|
47 | 'department_id' => $deptId,
|
---|
48 | 'version' => 1,
|
---|
49 | 'created_at' => now()
|
---|
50 | ];
|
---|
51 | }
|
---|
52 | }
|
---|