Skip to content

Commit

Permalink
Merge pull request #76 from rezaamini-ir/fe/configurable-table
Browse files Browse the repository at this point in the history
[ADD]  configure able model table
  • Loading branch information
reziamini authored Feb 1, 2024
2 parents 7e131c0 + 787ea09 commit 271c019
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
7 changes: 7 additions & 0 deletions config/easy_panel_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
];
12 changes: 10 additions & 2 deletions database/migrations/cruds_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@

class CreateCrudsTableEasypanel extends Migration
{
/**
* {@inheritdoc}
*/
public function getConnection()
{
return config('easy_panel_config.database.connection') ?: config('database.default');
}

/**
* Run the migrations.
*
* @return void
*/
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();
Expand All @@ -34,6 +42,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('cruds');
Schema::dropIfExists(config('easy_panel_config.database.crud_table'));
}
}
11 changes: 9 additions & 2 deletions database/migrations/panel_admins_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@

class CreatePanelAdminsTableEasypanel extends Migration
{
/**
* {@inheritdoc}
*/
public function getConnection()
{
return config('easy_panel_config.database.connection') ?: config('database.default');
}
/**
* Run the migrations.
*
* @return void
*/
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');
Expand All @@ -30,6 +37,6 @@ public function up()
*/
public function down()
{
Schema::dropIfExists('panel_admins');
Schema::dropIfExists(config('easy_panel_config.database.panel_admin_table'));
}
}
17 changes: 16 additions & 1 deletion src/Models/CRUD.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 17 additions & 1 deletion src/Models/PanelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 271c019

Please sign in to comment.