diff --git a/app/Models/GlobalParameter.php b/app/Models/GlobalParameter.php new file mode 100644 index 0000000..bfefcd4 --- /dev/null +++ b/app/Models/GlobalParameter.php @@ -0,0 +1,29 @@ +hasOne(GlobalParameterType::class, 'type', 'id'); + } + + public function createdByUser() :HasOne + { + return $this->hasOne(User::class, 'created_by', 'id'); + } + + public function updatedByUser() :HasOne + { + return $this->hasOne(User::class, 'updated_by', 'id'); + } +} diff --git a/app/Models/GlobalParameterType.php b/app/Models/GlobalParameterType.php new file mode 100644 index 0000000..b0d3293 --- /dev/null +++ b/app/Models/GlobalParameterType.php @@ -0,0 +1,30 @@ +hasMany(GlobalParameter::class, 'id'); + } + + public function createdByUser() :HasOne + { + return $this->hasOne(User::class, 'created_by', 'id'); + } + + public function updatedByUser() :HasOne + { + return $this->hasOne(User::class, 'updated_by', 'id'); + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index ae7354d..fc43bbd 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -17,8 +17,8 @@ public function up(): void $table->string('password'); $table->timestamp('email_verified_at')->nullable(); $table->boolean('is_active')->default(true); - $table->integer('created_by'); - $table->integer('updated_by'); + $table->integer('created_by')->nullable()->comment('users table primary key'); + $table->integer('updated_by')->nullable()->comment('users table primary key'); $table->timestamps(); $table->rememberToken(); }); diff --git a/database/migrations/2014_10_12_000001_create_users_profile_table.php b/database/migrations/2014_10_12_000001_create_users_profile_table.php index 82a5129..dce59dc 100644 --- a/database/migrations/2014_10_12_000001_create_users_profile_table.php +++ b/database/migrations/2014_10_12_000001_create_users_profile_table.php @@ -12,11 +12,14 @@ public function up(): void { Schema::create('users_profile', function (Blueprint $table) { - $table->id(); - $table->string('firstname'); - $table->string('lastname'); + $table->foreignId('id') + ->primary() + ->constrained('users') + ->onUpdate('cascade'); + $table->string('firstname')->nullable(); + $table->string('lastname')->nullable(); $table->string('middlename')->nullable(); - $table->integer('gender'); + $table->integer('gender')->comment('global parameters table primary key'); $table->timestamps(false); }); } diff --git a/database/migrations/2024_03_16_164013_create_global_parameters_type_table.php b/database/migrations/2024_03_16_164013_create_global_parameters_type_table.php new file mode 100644 index 0000000..c63faaf --- /dev/null +++ b/database/migrations/2024_03_16_164013_create_global_parameters_type_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('name')->nullable(); + $table->longText('description')->nullable(); + $table->boolean('is_active')->default(true); + $table->foreignId('created_by')->nullable()->constrained('users', 'id'); + $table->foreignId('updated_by')->nullable()->constrained('users', 'id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('global_parameters_type'); + } +}; diff --git a/database/migrations/2024_03_16_164726_create_global_parameters_table.php b/database/migrations/2024_03_16_164726_create_global_parameters_table.php new file mode 100644 index 0000000..436210d --- /dev/null +++ b/database/migrations/2024_03_16_164726_create_global_parameters_table.php @@ -0,0 +1,36 @@ +id(); + $table->foreignId('type') + ->nullable() + ->constrained('global_parameters_type') + ->onUpdate('cascade'); + $table->string('name')->nullable(); + $table->longText('description')->nullable(); + $table->boolean('is_active')->default(true); + $table->foreignId('created_by')->nullable()->constrained('users'); + $table->foreignId('updated_by')->nullable()->constrained('users'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('global_parameters'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 9c41bbe..e7af0fe 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -18,5 +18,11 @@ public function run(): void { User::factory(10)->create(); UserProfile::factory(10)->create(); + + $this->call([ + GlobalParameterTypeSeeder::class, + GlobalParameterSeeder::class, + + ]); } } diff --git a/database/seeders/GlobalParameterSeeder.php b/database/seeders/GlobalParameterSeeder.php new file mode 100644 index 0000000..cef3854 --- /dev/null +++ b/database/seeders/GlobalParameterSeeder.php @@ -0,0 +1,58 @@ + 1, + 'name' => 'Male', + ]); + GlobalParameter::create([ + 'type' => 1, + 'name' => 'Female', + ]); + + // Civil Status + GlobalParameter::create([ + 'type' => 2, + 'name' => 'Single', + ]); + GlobalParameter::create([ + 'type' => 2, + 'name' => 'Married', + ]); + GlobalParameter::create([ + 'type' => 2, + 'name' => 'Divorce', + ]); + GlobalParameter::create([ + 'type' => 2, + 'name' => 'Widowed', + ]); + + // Religion + GlobalParameter::create([ + 'type' => 3, + 'name' => 'Roman Catholic', + ]); + GlobalParameter::create([ + 'type' => 3, + 'name' => 'Muslim', + ]); + GlobalParameter::create([ + 'type' => 3, + 'name' => 'Iglesia ni Cristo', + ]); + } +} diff --git a/database/seeders/GlobalParameterTypeSeeder.php b/database/seeders/GlobalParameterTypeSeeder.php new file mode 100644 index 0000000..9bab15e --- /dev/null +++ b/database/seeders/GlobalParameterTypeSeeder.php @@ -0,0 +1,26 @@ + 'Gender', + ]); + GlobalParameterType::create([ + 'name' => 'Civil Status', + ]); + GlobalParameterType::create([ + 'name' => 'Religion', + ]); + } +}