Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] configure able model table #76

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading