Skip to content

Commit

Permalink
create migration for global parameters and global parameters type
Browse files Browse the repository at this point in the history
  • Loading branch information
koykoy027 committed Mar 16, 2024
1 parent 9584157 commit 37c779a
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 6 deletions.
29 changes: 29 additions & 0 deletions app/Models/GlobalParameter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;

class GlobalParameter extends Model
{
use HasFactory;
protected $table = 'global_parameters';
protected $guarded = [];

public function globalParameterType() :HasOne
{
return $this->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');
}
}
30 changes: 30 additions & 0 deletions app/Models/GlobalParameterType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class GlobalParameterType extends Model
{
use HasFactory;
protected $table = 'global_parameters_type';
protected $guarded = [];

public function globalParameter() :HasMany
{
return $this->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');
}
}
4 changes: 2 additions & 2 deletions database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('global_parameters_type', function (Blueprint $table) {
$table->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');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('global_parameters', function (Blueprint $table) {
$table->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');
}
};
6 changes: 6 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ public function run(): void
{
User::factory(10)->create();
UserProfile::factory(10)->create();

$this->call([
GlobalParameterTypeSeeder::class,
GlobalParameterSeeder::class,

]);
}
}
58 changes: 58 additions & 0 deletions database/seeders/GlobalParameterSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Database\Seeders;

use App\Models\GlobalParameter;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class GlobalParameterSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// Gender
GlobalParameter::create([
'type' => 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',
]);
}
}
26 changes: 26 additions & 0 deletions database/seeders/GlobalParameterTypeSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Database\Seeders;

use App\Models\GlobalParameterType;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class GlobalParameterTypeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
GlobalParameterType::create([
'name' => 'Gender',
]);
GlobalParameterType::create([
'name' => 'Civil Status',
]);
GlobalParameterType::create([
'name' => 'Religion',
]);
}
}

0 comments on commit 37c779a

Please sign in to comment.