mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 19:41:07 +03:30
feat: add factory for models
This commit is contained in:
Executable
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Cycle;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Cycle>
|
||||
*/
|
||||
class CycleFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'unique_id' => $this->faker->uuid,
|
||||
'date' => $this->faker->date,
|
||||
'sterilizer_id' => $this->faker->uuid,
|
||||
'cycle_number' => $this->faker->numerify('Cycle-####'),
|
||||
'note' => $this->faker->word,
|
||||
'verified' => $this->faker->randomElement(['Verified', 'NotVerified']),
|
||||
'user_id' => \App\Models\User::factory(),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Label;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
|
||||
*/
|
||||
class CycleLabelFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'label_id' => \App\Models\Label::factory(),
|
||||
'cycle_id' => \App\Models\Cycle::factory(),
|
||||
'count' => $this->faker->numberBetween(1, 10),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Gallery>
|
||||
*/
|
||||
class GalleryFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => \App\Models\User::factory(),
|
||||
'path' => $this->faker->imageUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Input>
|
||||
*/
|
||||
class InputFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->word,
|
||||
'type' => $this->faker->randomElement(['Text', 'Form', 'Checkbox', 'Select']),
|
||||
'test_type_id' => \App\Models\TestType::factory(),
|
||||
'parent_id' => null,
|
||||
'size' => $this->faker->word,
|
||||
'value' => $this->faker->word,
|
||||
'require_scanner' => $this->faker->boolean,
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\InputValue>
|
||||
*/
|
||||
class InputValueFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'value' => $this->faker->word,
|
||||
'option_id' => \App\Models\Option::factory(),
|
||||
'input_id' => \App\Models\Input::factory(),
|
||||
'test_result_id' => \App\Models\TestResult::factory(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Item>
|
||||
*/
|
||||
class ItemFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'package_id' => \App\Models\Package::factory(),
|
||||
'name' => $this->faker->word,
|
||||
'size' => $this->faker->word,
|
||||
'unique_id' => $this->faker->uuid,
|
||||
'specific' => $this->faker->word,
|
||||
'note' => $this->faker->word,
|
||||
'user_id' => \App\Models\User::factory(),
|
||||
'udi' => $this->faker->uuid,
|
||||
'repair' => $this->faker->boolean,
|
||||
'creator_id' => \App\Models\User::factory(),
|
||||
'status' => $this->faker->randomElement(['approved', 'rejected', 'suspended']),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Label>
|
||||
*/
|
||||
class LabelFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->word,
|
||||
'sterile_date' => $this->faker->date,
|
||||
'expire_date' => $this->faker->date,
|
||||
'sterilizer_id' => $this->faker->uuid,
|
||||
'cycle_number' => $this->faker->numerify('Cycle-####'),
|
||||
'lot_number' => $this->faker->word,
|
||||
'department' => $this->faker->word,
|
||||
'note' => $this->faker->word,
|
||||
'user_id' => \App\Models\User::factory(),
|
||||
'package_id' => \App\Models\Package::factory(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\MedicalCenter;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<MedicalCenter>
|
||||
*/
|
||||
class MedicalCenterFactory extends Factory
|
||||
{
|
||||
protected $model = MedicalCenter::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->company,
|
||||
'address' => $this->faker->address,
|
||||
'phone_number' => $this->faker->phoneNumber,
|
||||
'city_id' => 1,
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Message>
|
||||
*/
|
||||
class MessageFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->faker->word,
|
||||
'text' => $this->faker->word,
|
||||
'sender_user_id' => User::factory(),
|
||||
'recipient_user_id' => User::factory(),
|
||||
'status' => $this->faker->randomElement(['Read', 'UnRead']),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Input;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Option>
|
||||
*/
|
||||
class OptionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->faker->word,
|
||||
'input_id' => Input::factory(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
|
||||
*/
|
||||
class PackageFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->word,
|
||||
'note' => $this->faker->optional()->word,
|
||||
'user_id' => User::factory(), // ایجاد کاربر به طور خودکار
|
||||
'bar_code' => $this->faker->optional()->word,
|
||||
'qr_code' => $this->faker->optional()->word,
|
||||
'creator_id' => User::factory(), // ایجاد کاربر دیگر به عنوان creator
|
||||
'status' => $this->faker->randomElement(['approved', 'rejected', 'suspended']),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\TestType;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TestResult>
|
||||
*/
|
||||
class TestResultFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'info' => $this->faker->name,
|
||||
'cycle_number' => $this->faker->numberBetween(1000, 9999),
|
||||
'date' => $this->faker->date(),
|
||||
'result' => $this->faker->randomElement(['Accept', 'Reject']),
|
||||
'description' => $this->faker->word,
|
||||
'verified' => $this->faker->randomElement(['Verified', 'NotVerified', 'None']),
|
||||
'device_id' => $this->faker->uuid(),
|
||||
'user_id' => User::factory(),
|
||||
'test_type_id' => TestType::factory(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TestType>
|
||||
*/
|
||||
class TestTypeFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => Str::random(20),
|
||||
'unique_code' => Str::random(20),
|
||||
'bar_code' => $this->faker->word,
|
||||
'user_id' => User::factory(),
|
||||
'device_label' => $this->faker->randomElement([
|
||||
'AutoclaveID', 'WasherID', 'SterilizerID', 'WasherMachineID',
|
||||
'SealMachineID', 'PatientID', 'Set/PackID', 'MDID', 'ORID',
|
||||
'InstrumentID', 'ID', 'PersonalID'
|
||||
]),
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use App\Models\User;
|
||||
|
||||
class TransferFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
// Get a random model for polymorphic relationship
|
||||
$transferableModels = [
|
||||
\App\Models\Package::class,
|
||||
\App\Models\Item::class,
|
||||
];
|
||||
|
||||
$transferableType = $this->faker->randomElement($transferableModels);
|
||||
$transferable = $transferableType::factory()->create();
|
||||
|
||||
// Generate from_date and ensure to_date is after from_date
|
||||
$fromDate = $this->faker->dateTimeBetween('-1 year', 'now');
|
||||
$toDate = $this->faker->dateTimeBetween($fromDate, '+1 year');
|
||||
|
||||
return [
|
||||
'transferable_type' => $transferableType,
|
||||
'transferable_id' => $transferable->id,
|
||||
'user_id' => User::factory(),
|
||||
'from_date' => $fromDate,
|
||||
'to_date' => $toDate,
|
||||
'status' => $this->faker->randomElement(['approved', 'rejected', 'suspended']),
|
||||
'user_transfer_id' => User::factory(),
|
||||
'deleted_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the transfer is approved.
|
||||
*/
|
||||
public function approved(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'approved',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the transfer is rejected.
|
||||
*/
|
||||
public function rejected(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'rejected',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the transfer is suspended.
|
||||
*/
|
||||
public function suspended(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'suspended',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the transfer is soft deleted.
|
||||
*/
|
||||
public function deleted(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'deleted_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Gallery;
|
||||
use App\Models\Uploadable;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
|
||||
*/
|
||||
class UploadableFactory extends Factory
|
||||
{
|
||||
protected $model = Uploadable::class;
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'uploadable_id' => $this->faker->numberBetween(1, 100), // شناسهی تصادفی برای uploadable
|
||||
'uploadable_type' => $this->faker->word, // نوع تصادفی uploadable
|
||||
'gallery_id' => Gallery::factory(), // شناسهی تصادفی برای gallery (در صورتی که گالریها وجود داشته باشند)
|
||||
'image_role' => $this->faker->word, // نقش تصادفی برای تصویر (مثل 'thumbnail' یا 'featured')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\MedicalCenter;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -17,9 +18,17 @@ class UserFactory extends Factory
|
||||
return [
|
||||
'name' => $this->faker->name,
|
||||
'email' => $this->faker->unique()->safeEmail,
|
||||
'email_verified_at' => now(),
|
||||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
||||
'country_code' => '0098',
|
||||
'cell_number' => $this->faker->phoneNumber,
|
||||
'gender' => $this->faker->randomElement(['Male', 'FeMale']),
|
||||
'verified' => $this->faker->randomElement(['Verified', 'NotVerified']),
|
||||
'status' => $this->faker->randomElement(['Active', 'Suspended']),
|
||||
'medical_center_id' => MedicalCenter::factory(), // ایجاد مرکز پزشکی به طور خودکار
|
||||
'password' => bcrypt('password'), // رمز عبور پیشفرض
|
||||
'address' => $this->faker->optional()->address,
|
||||
'remember_token' => Str::random(10),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
@@ -11,6 +14,8 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// $this->call(UserTableSeeder::class);
|
||||
$this->call([
|
||||
TableSeeder::class
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
\App\Models\MedicalCenter::factory(10)->create();
|
||||
\App\Models\User::factory(10)->create();
|
||||
\App\Models\TestType::factory(10)->create();
|
||||
\App\Models\TestResult::factory(10)->create();
|
||||
\App\Models\Input::factory(10)->create();
|
||||
\App\Models\Option::factory(10)->create();
|
||||
\App\Models\InputValue::factory(10)->create();
|
||||
\App\Models\Gallery::factory(10)->create();
|
||||
\App\Models\Uploadable::factory(10)->create();
|
||||
\App\Models\Package::factory(10)->create();
|
||||
\App\Models\Item::factory(10)->create();
|
||||
\App\Models\Label::factory(10)->create();
|
||||
\App\Models\Cycle::factory(10)->create();
|
||||
\App\Models\Message::factory(10)->create();
|
||||
\App\Models\Transfer::factory(10)->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user