app/Http/Controllers/Admin/*Controller.php: refactoring so that all controllers share similar code by inheriting from BaseController and set $_datatable property.
This commit is contained in:
parent
6482020dfd
commit
0c493c2978
8 changed files with 76 additions and 116 deletions
|
|
@ -2,12 +2,22 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
class AdminController extends BaseController
|
||||||
|
|
||||||
class AdminController extends Controller
|
|
||||||
{
|
{
|
||||||
public function index()
|
protected $_datatable = [
|
||||||
{
|
'model' => \App\Models\Admin::class,
|
||||||
return view("admin.admin.index");
|
'default_sort' => 'id',
|
||||||
}
|
'columns' => [
|
||||||
|
'id' => '#',
|
||||||
|
'username' => 'Username',
|
||||||
|
'created_at' => 'Created',
|
||||||
|
'updated_at' => 'Updated',
|
||||||
|
],
|
||||||
|
'sort_columns' => [
|
||||||
|
'id' => 'id',
|
||||||
|
'username' => 'username',
|
||||||
|
'created_at' => 'created_at',
|
||||||
|
'updated_at' => 'updated_at',
|
||||||
|
]
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,32 @@ namespace App\Http\Controllers\Admin;
|
||||||
use App\Models\Card;
|
use App\Models\Card;
|
||||||
use App\Http\Livewire\Form\CardForm;
|
use App\Http\Livewire\Form\CardForm;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
class CardController extends BaseController
|
||||||
|
|
||||||
class CardController extends Controller
|
|
||||||
{
|
{
|
||||||
|
protected $_datatable = [
|
||||||
|
'model' => Card::class,
|
||||||
|
'default_sort' => 'id',
|
||||||
|
'route_create' => 'admin.card.create',
|
||||||
|
'route_edit' => 'admin.card.edit',
|
||||||
|
'delete_enabled' => true,
|
||||||
|
'restore_enabled' => true,
|
||||||
|
'columns' => [
|
||||||
|
'id' => '#',
|
||||||
|
'body' => 'Body',
|
||||||
|
'subject' => 'Subject',
|
||||||
|
'subject_type' => 'Subject Type',
|
||||||
|
'raid.name' => 'Raid',
|
||||||
|
],
|
||||||
|
'sort_columns' => [
|
||||||
|
'id' => 'id',
|
||||||
|
'body' => 'body',
|
||||||
|
'subject' => ['character.name', 'class', 'role'],
|
||||||
|
'raid.name' => 'raid.name',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
static public function getForm() : string
|
static public function getForm() : string
|
||||||
{
|
{
|
||||||
return CardForm::class;
|
return CardForm::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
return view('admin.card.index');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,27 @@ namespace App\Http\Controllers\Admin;
|
||||||
use App\Models\Character;
|
use App\Models\Character;
|
||||||
use App\Http\Livewire\Form\CharacterForm;
|
use App\Http\Livewire\Form\CharacterForm;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
class CharacterController extends BaseController
|
||||||
|
|
||||||
class CharacterController extends Controller
|
|
||||||
{
|
{
|
||||||
|
protected $_datatable = [
|
||||||
|
'model' => Character::class,
|
||||||
|
'default_sort' => 'id',
|
||||||
|
'route_create' => 'admin.character.create',
|
||||||
|
'route_edit' => 'admin.character.edit',
|
||||||
|
'delete_enabled' => true,
|
||||||
|
'restore_enabled' => true,
|
||||||
|
'columns' => [
|
||||||
|
'id' => '#',
|
||||||
|
'name' => 'Name',
|
||||||
|
],
|
||||||
|
'sort_columns' => [
|
||||||
|
'id' => 'id',
|
||||||
|
'name' => 'name',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
static public function getForm() : string
|
static public function getForm() : string
|
||||||
{
|
{
|
||||||
return CharacterForm::class;
|
return CharacterForm::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
return view("admin.character.index");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,27 @@ namespace App\Http\Controllers\Admin;
|
||||||
use App\Models\Raid;
|
use App\Models\Raid;
|
||||||
use App\Http\Livewire\Form\RaidForm;
|
use App\Http\Livewire\Form\RaidForm;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
class RaidController extends BaseController
|
||||||
|
|
||||||
class RaidController extends Controller
|
|
||||||
{
|
{
|
||||||
|
protected $_datatable = [
|
||||||
|
'model' => Raid::class,
|
||||||
|
'default_sort' => 'id',
|
||||||
|
'route_create' => 'admin.raid.create',
|
||||||
|
'route_edit' => 'admin.raid.edit',
|
||||||
|
'delete_enabled' => true,
|
||||||
|
'restore_enabled' => true,
|
||||||
|
'columns' => [
|
||||||
|
'id' => '#',
|
||||||
|
'name' => 'Name',
|
||||||
|
],
|
||||||
|
'sort_columns' => [
|
||||||
|
'id' => 'id',
|
||||||
|
'name' => 'name',
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
static public function getForm() : string
|
static public function getForm() : string
|
||||||
{
|
{
|
||||||
return RaidForm::class;
|
return RaidForm::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
return view("admin.raid.index");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<x-layout name="admin">
|
|
||||||
|
|
||||||
@livewire('datatable', [
|
|
||||||
'model' => \App\Models\Admin::class,
|
|
||||||
'default_sort' => 'id',
|
|
||||||
'columns' => [
|
|
||||||
'id' => '#',
|
|
||||||
'username' => 'Username',
|
|
||||||
'created_at' => 'Created',
|
|
||||||
'updated_at' => 'Updated',
|
|
||||||
],
|
|
||||||
'sort_columns' => [
|
|
||||||
'id' => 'id',
|
|
||||||
'username' => 'username',
|
|
||||||
'created_at' => 'created_at',
|
|
||||||
'updated_at' => 'updated_at'
|
|
||||||
]
|
|
||||||
])
|
|
||||||
|
|
||||||
</x-layout>
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
<x-layout name="admin">
|
|
||||||
|
|
||||||
@livewire('datatable', [
|
|
||||||
'model' => \App\Models\Card::class,
|
|
||||||
'default_sort' => 'id',
|
|
||||||
'route_create' => 'admin.card.create',
|
|
||||||
'route_edit' => 'admin.card.edit',
|
|
||||||
'delete_enabled' => true,
|
|
||||||
'restore_enabled' => true,
|
|
||||||
'columns' => [
|
|
||||||
'id' => '#',
|
|
||||||
'body' => 'Body',
|
|
||||||
'subject' => 'Subject',
|
|
||||||
'subject_type' => 'Subject Type',
|
|
||||||
'raid.name' => 'Raid',
|
|
||||||
],
|
|
||||||
'sort_columns' => [
|
|
||||||
'id' => 'id',
|
|
||||||
'body' => 'body',
|
|
||||||
'subject' => ['character.name', 'class', 'role'],
|
|
||||||
'raid.name' => 'raid.name',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
|
|
||||||
</x-layout>
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<x-layout name="admin">
|
|
||||||
|
|
||||||
@livewire('datatable', [
|
|
||||||
'model' => \App\Models\Character::class,
|
|
||||||
'default_sort' => 'id',
|
|
||||||
'route_create' => 'admin.character.create',
|
|
||||||
'route_edit' => 'admin.character.edit',
|
|
||||||
'delete_enabled' => true,
|
|
||||||
'restore_enabled' => true,
|
|
||||||
'columns' => [
|
|
||||||
'id' => '#',
|
|
||||||
'name' => 'Name',
|
|
||||||
],
|
|
||||||
'sort_columns' => [
|
|
||||||
'id' => 'id',
|
|
||||||
'name' => 'name',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
|
|
||||||
</x-layout>
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
<x-layout name="admin">
|
|
||||||
|
|
||||||
@livewire('datatable', [
|
|
||||||
'model' => \App\Models\Raid::class,
|
|
||||||
'default_sort' => 'id',
|
|
||||||
'route_create' => 'admin.raid.create',
|
|
||||||
'route_edit' => 'admin.raid.edit',
|
|
||||||
'delete_enabled' => true,
|
|
||||||
'restore_enabled' => true,
|
|
||||||
'columns' => [
|
|
||||||
'id' => '#',
|
|
||||||
'name' => 'Name',
|
|
||||||
],
|
|
||||||
'sort_columns' => [
|
|
||||||
'id' => 'id',
|
|
||||||
'name' => 'name',
|
|
||||||
]
|
|
||||||
])
|
|
||||||
|
|
||||||
</x-layout>
|
|
||||||
Reference in a new issue