This commit is contained in:
glovetleong
2021-06-17 09:53:04 +08:00
commit 8fa80e4a1a
2382 changed files with 196486 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
*.sqlite
*.sqlite-journal
+47
View File
@@ -0,0 +1,47 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function unverified()
{
return $this->state(function (array $attributes) {
return [
'email_verified_at' => null,
];
});
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateFailedJobsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('failed_jobs');
}
}
@@ -0,0 +1,62 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthAuthCodesTable extends Migration
{
/**
* The database schema.
*
* @var \Illuminate\Database\Schema\Builder
*/
protected $schema;
/**
* Create a new migration instance.
*
* @return void
*/
public function __construct()
{
$this->schema = Schema::connection($this->getConnection());
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->schema->create('oauth_auth_codes', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->unsignedBigInteger('user_id')->index();
$table->unsignedBigInteger('client_id');
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$this->schema->dropIfExists('oauth_auth_codes');
}
/**
* Get the migration connection name.
*
* @return string|null
*/
public function getConnection()
{
return config('passport.storage.database.connection');
}
}
@@ -0,0 +1,64 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthAccessTokensTable extends Migration
{
/**
* The database schema.
*
* @var \Illuminate\Database\Schema\Builder
*/
protected $schema;
/**
* Create a new migration instance.
*
* @return void
*/
public function __construct()
{
$this->schema = Schema::connection($this->getConnection());
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->schema->create('oauth_access_tokens', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->unsignedBigInteger('user_id')->nullable()->index();
$table->unsignedBigInteger('client_id');
$table->string('name')->nullable();
$table->text('scopes')->nullable();
$table->boolean('revoked');
$table->timestamps();
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$this->schema->dropIfExists('oauth_access_tokens');
}
/**
* Get the migration connection name.
*
* @return string|null
*/
public function getConnection()
{
return config('passport.storage.database.connection');
}
}
@@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthRefreshTokensTable extends Migration
{
/**
* The database schema.
*
* @var \Illuminate\Database\Schema\Builder
*/
protected $schema;
/**
* Create a new migration instance.
*
* @return void
*/
public function __construct()
{
$this->schema = Schema::connection($this->getConnection());
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->schema->create('oauth_refresh_tokens', function (Blueprint $table) {
$table->string('id', 100)->primary();
$table->string('access_token_id', 100)->index();
$table->boolean('revoked');
$table->dateTime('expires_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$this->schema->dropIfExists('oauth_refresh_tokens');
}
/**
* Get the migration connection name.
*
* @return string|null
*/
public function getConnection()
{
return config('passport.storage.database.connection');
}
}
@@ -0,0 +1,66 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthClientsTable extends Migration
{
/**
* The database schema.
*
* @var \Illuminate\Database\Schema\Builder
*/
protected $schema;
/**
* Create a new migration instance.
*
* @return void
*/
public function __construct()
{
$this->schema = Schema::connection($this->getConnection());
}
/**
* Get the migration connection name.
*
* @return string|null
*/
public function getConnection()
{
return config('passport.storage.database.connection');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->schema->create('oauth_clients', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->nullable()->index();
$table->string('name');
$table->string('secret', 100)->nullable();
$table->string('provider')->nullable();
$table->text('redirect');
$table->boolean('personal_access_client');
$table->boolean('password_client');
$table->boolean('revoked');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$this->schema->dropIfExists('oauth_clients');
}
}
@@ -0,0 +1,59 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateOauthPersonalAccessClientsTable extends Migration
{
/**
* The database schema.
*
* @var \Illuminate\Database\Schema\Builder
*/
protected $schema;
/**
* Create a new migration instance.
*
* @return void
*/
public function __construct()
{
$this->schema = Schema::connection($this->getConnection());
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$this->schema->create('oauth_personal_access_clients', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('client_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$this->schema->dropIfExists('oauth_personal_access_clients');
}
/**
* Get the migration connection name.
*
* @return string|null
*/
public function getConnection()
{
return config('passport.storage.database.connection');
}
}
@@ -0,0 +1,116 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePermissionTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$tableNames = config('permission.table_names');
$columnNames = config('permission.column_names');
if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
}
Schema::create($tableNames['permissions'], function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('guard_name');
$table->integer('status')->nullable()->default(1);
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
Schema::create($tableNames['roles'], function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('guard_name');
$table->integer('status')->nullable()->default(1);
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) {
$table->unsignedBigInteger('permission_id');
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
$table->foreign('permission_id')
->references('id')
->on($tableNames['permissions'])
->onDelete('cascade');
$table->primary(['permission_id', $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary');
});
Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
$table->unsignedBigInteger('role_id');
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
$table->foreign('role_id')
->references('id')
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary(['role_id', $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary');
});
Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
$table->unsignedBigInteger('permission_id');
$table->unsignedBigInteger('role_id');
$table->foreign('permission_id')
->references('id')
->on($tableNames['permissions'])
->onDelete('cascade');
$table->foreign('role_id')
->references('id')
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary(['permission_id', 'role_id'], 'role_has_permissions_permission_id_role_id_primary');
});
app('cache')
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
->forget(config('permission.cache.key'));
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$tableNames = config('permission.table_names');
if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
}
Schema::drop($tableNames['role_has_permissions']);
Schema::drop($tableNames['model_has_roles']);
Schema::drop($tableNames['model_has_permissions']);
Schema::drop($tableNames['roles']);
Schema::drop($tableNames['permissions']);
}
}
@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('first_name');
$table->string('last_name');
$table->string('username');
$table->string('email')->unique();
$table->string('password');
$table->json('img')->nullable();
$table->integer('status')->nullable()->default(1);
$table->timestamp('active_at')->nullable();
$table->timestamp('login_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUserLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_logs', function (Blueprint $table) {
$table->id();
$table->bigInteger('user_id')->unsigned()->nullable();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->json('history')->nullable();
$table->text('remark')->nullable();
$table->integer('status')->nullable()->default(1);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_logs');
}
}
@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAdminsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admins', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->json('img')->nullable();
$table->integer('status')->nullable()->default(1);
$table->bigInteger('created_by')->unsigned()->nullable();
$table->foreign('created_by')->references('id')->on('admins')->onDelete('cascade');
$table->bigInteger('updated_by')->unsigned()->nullable();
$table->foreign('updated_by')->references('id')->on('admins')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('admins');
}
}
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAdminLogsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('admin_logs', function (Blueprint $table) {
$table->id();
$table->bigInteger('admin_id')->unsigned()->nullable();
$table->foreign('admin_id')->references('id')->on('admins')->onDelete('cascade');
$table->json('history')->nullable();
$table->text('remark')->nullable();
$table->integer('status')->nullable()->default(1);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('admin_logs');
}
}
@@ -0,0 +1,136 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use Illuminate\Support\Facades\DB;
use App\Models\Admin;
class AdminPermissionsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Reset cached roles and permissions
app()['cache']->forget('spatie.permission.cache');
// admin permissions
Permission::create(['name' => 'view keyword', 'guard_name' => 'admin']);
Permission::create(['name' => 'add keyword', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit keyword', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete keyword', 'guard_name' => 'admin']);
Permission::create(['name' => 'view admin', 'guard_name' => 'admin']);
Permission::create(['name' => 'add admin', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit admin', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete admin', 'guard_name' => 'admin']);
Permission::create(['name' => 'view user', 'guard_name' => 'admin']);
Permission::create(['name' => 'add user', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit user', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete user', 'guard_name' => 'admin']);
Permission::create(['name' => 'view contributor', 'guard_name' => 'admin']);
Permission::create(['name' => 'add contributor', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit contributor', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete contributor', 'guard_name' => 'admin']);
Permission::create(['name' => 'view reviewer', 'guard_name' => 'admin']);
Permission::create(['name' => 'add reviewer', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit reviewer', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete reviewer', 'guard_name' => 'admin']);
Permission::create(['name' => 'view role', 'guard_name' => 'admin']);
Permission::create(['name' => 'add role', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit role', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete role', 'guard_name' => 'admin']);
Permission::create(['name' => 'view permission', 'guard_name' => 'admin']);
Permission::create(['name' => 'add permission', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit permission', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete permission', 'guard_name' => 'admin']);
Permission::create(['name' => 'view mime_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'add mime_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit mime_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete mime_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'view media_property_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'add media_property_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit media_property_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete media_property_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'view license_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'add license_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit license_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete license_type', 'guard_name' => 'admin']);
Permission::create(['name' => 'view country', 'guard_name' => 'admin']);
Permission::create(['name' => 'add country', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit country', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete country', 'guard_name' => 'admin']);
Permission::create(['name' => 'view language', 'guard_name' => 'admin']);
Permission::create(['name' => 'add language', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit language', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete language', 'guard_name' => 'admin']);
Permission::create(['name' => 'view currency', 'guard_name' => 'admin']);
Permission::create(['name' => 'add currency', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit currency', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete currency', 'guard_name' => 'admin']);
Permission::create(['name' => 'view system_bank', 'guard_name' => 'admin']);
Permission::create(['name' => 'add system_bank', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit system_bank', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete system_bank', 'guard_name' => 'admin']);
Permission::create(['name' => 'view package', 'guard_name' => 'admin']);
Permission::create(['name' => 'add package', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit package', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete package', 'guard_name' => 'admin']);
Permission::create(['name' => 'view on_demand_credit', 'guard_name' => 'admin']);
Permission::create(['name' => 'add on_demand_credit', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit on_demand_credit', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete on_demand_credit', 'guard_name' => 'admin']);
Permission::create(['name' => 'view subscription_plan', 'guard_name' => 'admin']);
Permission::create(['name' => 'add subscription_plan', 'guard_name' => 'admin']);
Permission::create(['name' => 'edit subscription_plan', 'guard_name' => 'admin']);
Permission::create(['name' => 'delete subscription_plan', 'guard_name' => 'admin']);
///////////////////////////////////////////////////////////////////////
$shadow_admin_role = Role::create([
'name' => 'Shadow Admin',
'guard_name' => 'admin',
'status' => 1
]);
$shadow_admin_role->givePermissionTo(Permission::where('guard_name', 'admin')->get());
$admin = Admin::find(1);
$admin->assignRole($shadow_admin_role);
///////////////////////////////////////////////////////////////////////
$ultimate_admin_role = Role::create([
'name' => 'Ultimate Admin',
'guard_name' => 'admin',
'status' => 1
]);
$ultimate_admin_role->givePermissionTo(Permission::where('guard_name', 'admin')->get());
$admin = Admin::find(2);
$admin->assignRole($ultimate_admin_role);
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
class AdminsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('admins')->insert([
[
'id' => 1,
'name' => 'Glovetloxad',
'email' => 'glovet@unity.com',
'password' => bcrypt('pass123'),
'img' => null,
'status' => 1,
'created_by' => null,
'updated_by' => null,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
],
[
'id' => 2,
'name' => 'The One',
'email' => 'admin@unity.com',
'password' => bcrypt('pass123'),
'img' => null,
'status' => 1,
'created_by' => null,
'updated_by' => null,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
]
]);
}
}
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
DB::beginTransaction();
// Admin
$this->call(AdminsTableSeeder::class);
$this->call(AdminPermissionsTableSeeder::class);
// User
$this->call(UsersTableSeeder::class);
DB::commit();
}
}
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
class UsersTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert([
[
'id' => 1,
'first_name' => 'izyim',
'last_name' => 'project',
'username' => 'calvin',
'email' => 'one@izyim.com',
'password' => bcrypt('pass123'),
'img' => null,
'status' => 1,
'active_at' => date('Y-m-d H:i:s'),
'login_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s')
]
]);
}
}