-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create migration for global parameters and global parameters type
- Loading branch information
Showing
9 changed files
with
226 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
database/migrations/2024_03_16_164013_create_global_parameters_type_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |
36 changes: 36 additions & 0 deletions
36
database/migrations/2024_03_16_164726_create_global_parameters_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]); | ||
} | ||
} |