From 787ea090635f7baf43ef47abd4a979b08b540b84 Mon Sep 17 00:00:00 2001 From: Amin Sharifi Date: Tue, 30 Jan 2024 18:35:14 +0330 Subject: [PATCH] [ADD] configure able model table [needToTest] --- config/easy_panel_config.php | 7 +++++++ database/migrations/cruds_table.php | 12 ++++++++++-- database/migrations/panel_admins_table.php | 11 +++++++++-- src/Models/CRUD.php | 17 ++++++++++++++++- src/Models/PanelAdmin.php | 18 +++++++++++++++++- 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/config/easy_panel_config.php b/config/easy_panel_config.php index 4781b16..e862577 100644 --- a/config/easy_panel_config.php +++ b/config/easy_panel_config.php @@ -41,4 +41,11 @@ // Lazy validation for Livewire components 'lazy_mode' => true, + + // database configure + 'database'=>[ + 'connection'=> env('EZ_PANEL_DB_CONNECTION'), + 'panel_admin_table'=>'panel_admins', + 'crud_table'=> 'cruds' + ] ]; diff --git a/database/migrations/cruds_table.php b/database/migrations/cruds_table.php index 26275a4..0cb04ad 100644 --- a/database/migrations/cruds_table.php +++ b/database/migrations/cruds_table.php @@ -6,6 +6,14 @@ class CreateCrudsTableEasypanel extends Migration { + /** + * {@inheritdoc} + */ + public function getConnection() + { + return config('easy_panel_config.database.connection') ?: config('database.default'); + } + /** * Run the migrations. * @@ -13,7 +21,7 @@ class CreateCrudsTableEasypanel extends Migration */ public function up() { - Schema::create('cruds', function (Blueprint $table) { + Schema::create(config('easy_panel_config.database.crud_table'), function (Blueprint $table) { $table->id(); $table->string('name')->unique(); $table->string('model')->unique(); @@ -34,6 +42,6 @@ public function up() */ public function down() { - Schema::dropIfExists('cruds'); + Schema::dropIfExists(config('easy_panel_config.database.crud_table')); } } diff --git a/database/migrations/panel_admins_table.php b/database/migrations/panel_admins_table.php index c064080..139aab1 100644 --- a/database/migrations/panel_admins_table.php +++ b/database/migrations/panel_admins_table.php @@ -6,6 +6,13 @@ class CreatePanelAdminsTableEasypanel extends Migration { + /** + * {@inheritdoc} + */ + public function getConnection() + { + return config('easy_panel_config.database.connection') ?: config('database.default'); + } /** * Run the migrations. * @@ -13,7 +20,7 @@ class CreatePanelAdminsTableEasypanel extends Migration */ public function up() { - Schema::create('panel_admins', function (Blueprint $table) { + Schema::create(config('easy_panel_config.database.panel_admin_table'), function (Blueprint $table) { $table->id(); $table->foreignId('user_id')->constrained(); $table->boolean('is_superuser'); @@ -30,6 +37,6 @@ public function up() */ public function down() { - Schema::dropIfExists('panel_admins'); + Schema::dropIfExists(config('easy_panel_config.database.panel_admin_table')); } } diff --git a/src/Models/CRUD.php b/src/Models/CRUD.php index d448f9a..9f0fb50 100644 --- a/src/Models/CRUD.php +++ b/src/Models/CRUD.php @@ -8,7 +8,22 @@ class CRUD extends Model { - protected $table = 'cruds'; + /** + * Create a new Eloquent model instance. + * + * @param array $attributes + */ + public function __construct(array $attributes = []) + { + $connection = config('easy_panel_config.database.connection') ?: config('database.default'); + + $this->setConnection($connection); + + $this->setTable(config('easy_panel_config.database.crud_table')); + + parent::__construct($attributes); + } + protected $guarded = []; public function scopeActive($query) diff --git a/src/Models/PanelAdmin.php b/src/Models/PanelAdmin.php index 55935ed..855fb1f 100644 --- a/src/Models/PanelAdmin.php +++ b/src/Models/PanelAdmin.php @@ -8,7 +8,23 @@ class PanelAdmin extends Model { - protected $table = 'panel_admins'; + + /** + * Create a new Eloquent model instance. + * + * @param array $attributes + */ + public function __construct(array $attributes = []) + { + $connection = config('easy_panel_config.database.connection') ?: config('database.default'); + + $this->setConnection($connection); + + $this->setTable(config('easy_panel_config.database.panel_admin_table')); + + parent::__construct($attributes); + } + protected $guarded = []; public function user()