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