mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/portal.git
synced 2026-08-28 17:04:18 +00:00
fix migration files and add admin user seeder
This commit is contained in:
@@ -4,19 +4,14 @@ namespace App\Classes\Modules\Accounts\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class FullnameObject implements DataTransferObject
|
||||
class FullNameObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* UserObject constructor.
|
||||
* FullNameObject constructor.
|
||||
* @param string $name
|
||||
* @param string $email
|
||||
* @param string $password
|
||||
* @param string $passwordConfirmation
|
||||
* @param int|null $type
|
||||
* @param int|null $status
|
||||
*/
|
||||
public function __construct(string $name)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\FullnameObject;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\FullNameObject;
|
||||
use App\Models\User;
|
||||
|
||||
class UpdatesUser extends AbstractUpdateRecord
|
||||
@@ -11,7 +11,7 @@ class UpdatesUser extends AbstractUpdateRecord
|
||||
|
||||
/**
|
||||
* @param User $model
|
||||
* @param UserObject $object
|
||||
* @param FullNameObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@@ -17,9 +19,11 @@ class CreateUsersTable extends Migration
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->integer('type')->default(RoleTypes::USER);
|
||||
$table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION);
|
||||
$table->rememberToken();
|
||||
$table->timestamp('active_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,9 +14,14 @@ class CreatePasswordResetsTable extends Migration
|
||||
public function up()
|
||||
{
|
||||
Schema::create('password_resets', function (Blueprint $table) {
|
||||
$table->string('email')->index();
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->unsigned();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
$table->boolean('is_expired')->default(true);
|
||||
$table->boolean('is_complete')->default(false);
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ModifyUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
if (Schema::hasColumn('users', 'email_verified_at')) {
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropColumn('email_verified_at');
|
||||
});
|
||||
}
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->integer('type')->default(RoleTypes::USER)->after('password');
|
||||
$table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION)->after('type');
|
||||
$table->timestamp('active_at')->nullable()->after('remember_token');
|
||||
$table->softDeletes()->after('active_at');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->dropColumn('type');
|
||||
$table->dropColumn('status');
|
||||
$table->dropColumn('active_at');
|
||||
$table->dropSoftDeletes();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class ModifyPasswordResetsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('password_resets', function (Blueprint $table) {
|
||||
//
|
||||
$table->id()->first();
|
||||
$table->dropColumn('email');
|
||||
$table->foreignId('user_id')->unsigned()->after('id');
|
||||
$table->boolean('is_expired')->default(true)->after('token');
|
||||
$table->boolean('is_complete')->default(false)->after('is_expired');
|
||||
$table->timestamp('updated_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('password_resets', function (Blueprint $table) {
|
||||
//
|
||||
$table->string('email')->index()->first();
|
||||
$table->dropColumn('id');
|
||||
$table->dropColumn('user_id');
|
||||
$table->dropColumn('is_expired');
|
||||
$table->dropColumn('is_complete');
|
||||
$table->dropColumn('updated_at');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class AdminUsersTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
[
|
||||
'name' => 'Shadow Admin',
|
||||
'email' => 'omair@cief-malaysia.com',
|
||||
'password' => bcrypt('123456abcabc'),
|
||||
'type' => RoleTypes::SHADOW_ADMIN,
|
||||
'status' => ApprovalStatus::APPROVED,
|
||||
],
|
||||
[
|
||||
'name' => 'Admin',
|
||||
'email' => 'admin@cief-malaysia.com',
|
||||
'password' => bcrypt('123456abcabc'),
|
||||
'type' => RoleTypes::ADMIN,
|
||||
'status' => ApprovalStatus::APPROVED,
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Classes\Modules\Countries\DataTransferObjects\CountryObject;
|
||||
use App\Classes\Modules\Countries\Services\CreatesCountry;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class CountriesTableSeeder extends Seeder
|
||||
{
|
||||
|
||||
/** @var CreatesCountry */
|
||||
private $createsCountry;
|
||||
|
||||
/**
|
||||
* CountriesTableSeeder constructor.
|
||||
* @param CreatesCountry $createsCountry
|
||||
*/
|
||||
public function __construct(CreatesCountry $createsCountry)
|
||||
{
|
||||
$this->createsCountry = $createsCountry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
foreach (['my', 'cn'] as $code) {
|
||||
$object = new CountryObject(country($code));
|
||||
$this->createsCountry->execute($object);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// \App\Models\User::factory(10)->create();
|
||||
$this->call(AdminUsersTableSeeder::class);
|
||||
|
||||
$this->call(CountriesTableSeeder::class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user