Archived
1
0
Fork 0

Livewire Datatable: include "create" button.

This commit is contained in:
Henrik Hautakoski 2022-01-22 15:33:02 +01:00
parent 2f53055c80
commit 2382387233
5 changed files with 13 additions and 13 deletions

View file

@ -36,6 +36,8 @@ class Datatable extends Component
*/ */
public array $sort_columns; public array $sort_columns;
public $route_create;
/** /**
* Route for editing a record (if null, link is omitted) * Route for editing a record (if null, link is omitted)
*/ */
@ -52,11 +54,12 @@ class Datatable extends Component
public int $itemsPerPage = 30; public int $itemsPerPage = 30;
public function mount(string $model, array $columns, array $sort_columns = [], public function mount(string $model, array $columns, array $sort_columns = [],
$default_sort = '', $route_delete = null, $route_edit = null) $default_sort = '', $route_create = null, $route_delete = null, $route_edit = null)
{ {
$this->model = app()->make($model); $this->model = app()->make($model);
$this->sort = $default_sort; $this->sort = $default_sort;
$this->sort_columns = $sort_columns; $this->sort_columns = $sort_columns;
$this->route_create = $route_create;
$this->route_edit = $route_edit; $this->route_edit = $route_edit;
$this->route_delete = $route_delete; $this->route_delete = $route_delete;
} }

View file

@ -1,12 +1,9 @@
<x-layout name="admin"> <x-layout name="admin">
<div class="mb-4">
<x-button href="{{ route('admin.card.create') }}" type="info">{{ __('New') }}</x-button>
</div>
@livewire('datatable', [ @livewire('datatable', [
'model' => \App\Models\Card::class, 'model' => \App\Models\Card::class,
'default_sort' => 'id', 'default_sort' => 'id',
'route_create' => 'admin.card.create',
'route_edit' => 'admin.card.edit', 'route_edit' => 'admin.card.edit',
'route_delete' => 'admin.card.delete', 'route_delete' => 'admin.card.delete',
'columns' => [ 'columns' => [

View file

@ -1,12 +1,9 @@
<x-layout name="admin"> <x-layout name="admin">
<div class="mb-4">
<x-button href="{{ route('admin.character.create') }}" type="info">{{ __('New') }}</x-button>
</div>
@livewire('datatable', [ @livewire('datatable', [
'model' => \App\Models\Character::class, 'model' => \App\Models\Character::class,
'default_sort' => 'id', 'default_sort' => 'id',
'route_create' => 'admin.character.create',
'route_edit' => 'admin.character.edit', 'route_edit' => 'admin.character.edit',
'route_delete' => 'admin.character.delete', 'route_delete' => 'admin.character.delete',
'columns' => [ 'columns' => [

View file

@ -1,12 +1,9 @@
<x-layout name="admin"> <x-layout name="admin">
<div class="mb-4">
<x-button href="{{ route('admin.raid.create') }}" type="info">{{ __('New') }}</x-button>
</div>
@livewire('datatable', [ @livewire('datatable', [
'model' => \App\Models\Raid::class, 'model' => \App\Models\Raid::class,
'default_sort' => 'id', 'default_sort' => 'id',
'route_create' => 'admin.raid.create',
'route_edit' => 'admin.raid.edit', 'route_edit' => 'admin.raid.edit',
'route_delete' => 'admin.raid.delete', 'route_delete' => 'admin.raid.delete',
'columns' => [ 'columns' => [

View file

@ -1,5 +1,11 @@
<div> <div>
@if ($route_create)
<div class="mb-4">
<x-button :href="route($route_create)" type="info">{{ __('New') }}</x-button>
</div>
@endif
<table class="table-auto w-full"> <table class="table-auto w-full">
<tr class="text-left border-b-2"> <tr class="text-left border-b-2">