@if ($withUnlock && !empty($record['locked']) && $routeUnlock)
@include('playground::components/table/data-row-actions-unlock')
@else
diff --git a/resources/views/components/table/data-row.blade.php b/resources/views/components/table/data-row.blade.php
index ca6199f..b2dfd3d 100644
--- a/resources/views/components/table/data-row.blade.php
+++ b/resources/views/components/table/data-row.blade.php
@@ -6,6 +6,8 @@
$routeParameter = !empty($routeParameter) && is_string($routeParameter) ? $routeParameter : '';
$record = !empty($record) && is_array($record) ? $record : [];
+ $fkModelData = [];
+
$hasColumnError = false;
/**
@@ -63,7 +65,7 @@
/**
* @var string $isFk Is the column a foreign key?
*/
- $isFk = 'fk' === $columnMeta['linkType'];
+ $isFk = in_array($columnMeta['linkType'], ['fk', 'filter-id']);
// The foreign key needs a property to access.
$isFk = $isFk && isset($columnMeta['property']) && !empty($columnMeta['property']);
if ($preferLinkSlug) {
@@ -85,7 +87,10 @@
// '$isUrlLink' => $isUrlLink,
// '$link' => $link,
// '$record' => $record,
- // '$datum' => $datum,
+ // // '$datum' => $datum,
+ // '$routeParameter' => $routeParameter,
+ // '$routeParameterKey' => $routeParameterKey,
+ // '$record[$routeParameterKey]' => $record[$routeParameterKey] ?? 'nope',
// ]);
// Check for slug link first.
@@ -98,7 +103,11 @@
} elseif ($preferLinkGo) {
$link = empty($record[$routeParameterKey]) ? '' : route($columnMeta['linkRoute'], ['go' => $record[$routeParameterKey]]);
} elseif ($isFk) {
- $link = empty($record[$column]) ? '' : route($columnMeta['linkRoute'], [$routeParameter => $record[$column]]);
+ if (!empty($record[$column]) && !empty($columnMeta['routeParameter']) && !empty($columnMeta['routeParameterKey'])) {
+ $link = route($columnMeta['linkRoute'], [
+ $columnMeta['routeParameter'] => $record[$columnMeta['routeParameterKey']],
+ ]);
+ }
}
if ($isUrlLink) {
@@ -117,8 +126,8 @@
// '$isFk' => $isFk,
// '$isUrlLink' => $isUrlLink,
// '$link' => $link,
- // '$record' => $record,
- // '$datum' => $datum,
+ // // '$record' => $record,
+ // // '$datum' => $datum,
// ]);
if ($isFk && !empty($accessor)) {
@@ -126,8 +135,12 @@
$fkModel = $datum && is_callable([$datum, $accessor]) ? $datum->{$accessor}()->first() : null;
if ($fkModel) {
$fkModelData = $fkModel->toArray();
- if (!empty($property) && isset($fkModelData[$property])) {
- $value = $fkModelData[$property];
+ if (!empty($property)) {
+ if ($property === 'label_or_title') {
+ $value = $fkModel->label_or_title;
+ } elseif (isset($fkModelData[$property])) {
+ $value = $fkModelData[$property];
+ }
}
}
} catch (\Throwable $th) {
@@ -170,6 +183,7 @@
}
$isFlag = isset($columnMeta['flag']) && is_bool($columnMeta['flag']) && $columnMeta['flag'];
+ $withImage = isset($columnMeta['with-image']) && is_bool($columnMeta['with-image']) && $columnMeta['with-image'];
// dump([
// '__METHOD__' => __METHOD__,
@@ -195,6 +209,8 @@ class="{{ !empty($hasColumnError) ? 'text-danger ' : '' }}{{ !empty($columnMeta[
@if ($isFlag)
+ @elseif ($withImage)
+
@elseif ($columnMeta['html'])
{!! $value !!}
@elseif ($isDate)
diff --git a/resources/views/layouts/resource/detail-accordion.blade.php b/resources/views/layouts/resource/detail-accordion.blade.php
new file mode 100644
index 0000000..82a8481
--- /dev/null
+++ b/resources/views/layouts/resource/detail-accordion.blade.php
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+ @include('playground::layouts.resource.detail-actions', ['css' => 'mb-3'])
+
+ @yield('detail-accordion-body-header')
+ @yield('detail-accordion-body')
+ @includeWhen($withInfo, 'playground::layouts.resource.detail-info')
+
+ @if ($withAccordionFlags)
+
+
+ @yield('detail-information-flags')
+
+
+ @endif
+
+ @if ($withAccordionTimestamps)
+
+
+ @include('playground::layouts.resource.detail-timestamps')
+
+
+ @endif
+
+ @yield('detail-accordion-body-footer')
+
+
+
+
diff --git a/resources/views/layouts/resource/detail-actions.blade.php b/resources/views/layouts/resource/detail-actions.blade.php
new file mode 100644
index 0000000..91f6580
--- /dev/null
+++ b/resources/views/layouts/resource/detail-actions.blade.php
@@ -0,0 +1,52 @@
+@if ($withDelete || $withEdit)
+
+
+
+ @else
+ @if(!$data->locked)
+
+ {{ __('Edit') }}
+
+ @endif
+ @endif
+ @if($data->locked)
+
+ @else
+ @if(!$data->trashed())
+
+
+ @endif
+ @endif
+
+
+@endif
diff --git a/resources/views/layouts/resource/detail-card.blade.php b/resources/views/layouts/resource/detail-card.blade.php
new file mode 100644
index 0000000..3a5585f
--- /dev/null
+++ b/resources/views/layouts/resource/detail-card.blade.php
@@ -0,0 +1,34 @@
+
+ @if($withCardHeader)
+
+ @endif
+ @if ($withImage && $data && $data->image)
+
+ @endif
+ @if($withCardBody)
+
+ @yield('detail-card-body-header')
+ @yield('detail-card-body')
+ @includeWhen($withInfo, 'playground::layouts.resource.detail-info')
+ @yield('detail-card-body-footer')
+
+ @endif
+
+ @if($withCardFlags)
+
+ @endif
+
+ @if($withCardTimestamps)
+
+ @endif
+
+
diff --git a/resources/views/layouts/resource/detail-flags.blade.php b/resources/views/layouts/resource/detail-flags.blade.php
new file mode 100644
index 0000000..f534764
--- /dev/null
+++ b/resources/views/layouts/resource/detail-flags.blade.php
@@ -0,0 +1,17 @@
+@if(!empty($data) && $data->deleted_at)
+
+
+ {{ __('Trashed') }}
+
+@endif
+
+@if(!empty($flags) && is_array($flags))
+@foreach ($flags as $flagKey => $flagMeta)
+@if ($data->getAttribute($flagKey))
+
+
+ {{ __($flagMeta['label']) }}
+
+@endif
+@endforeach
+@endif
diff --git a/resources/views/layouts/resource/detail-info.blade.php b/resources/views/layouts/resource/detail-info.blade.php
new file mode 100644
index 0000000..a5fa033
--- /dev/null
+++ b/resources/views/layouts/resource/detail-info.blade.php
@@ -0,0 +1,48 @@
+
+
+ @yield('detail-info-table-header')
+
+
+ {{ __('Slug') }} |
+ {{ $data->slug }} |
+
+ @yield('detail-info-table-body')
+ @if ($parent)
+
+ {{ __('Parent ' . $meta['info']['model_label']) }} |
+
+
+ {{ __($parent->label) }}
+
+ |
+
+ @endif
+
+ @yield('detail-info-table-header')
+
+
+
+@if ($data->description)
+
{{ __('Description') }}
+
+
{{ $data->description }}
+@endif
+
+@if ($data->introduction)
+
{{ __('Introduction') }}
+
+
{{ $data->introduction }}
+@endif
+
+@if ($data->content)
+
{{ __('Content') }}
+
+
{!! $data->content !!}
+@endif
+
+@if ($data->summary)
+
{{ __('Summary') }}
+
+
{!! $data->summary !!}
+@endif
diff --git a/resources/views/layouts/resource/detail-information.blade.php b/resources/views/layouts/resource/detail-information.blade.php
deleted file mode 100644
index bf55649..0000000
--- a/resources/views/layouts/resource/detail-information.blade.php
+++ /dev/null
@@ -1,130 +0,0 @@
-
-
- @if ($withImage && $data && $data->image)
-
- @endif
-
-
-
{{ __('Information') }}
-
-
-
-
- {{ __('Slug') }} |
- {{ $data->slug }} |
-
- @if ($parent)
-
- {{ __('Parent ' . $meta['info']['model_label']) }} |
-
-
- {{ $parent->label }}
-
- |
-
- @endif
-
- {{ __('Created') }} |
-
- @if ($data->created_at)
-
- @endif
- |
-
-
- {{ __('Updated') }} |
-
- @if ($data->updated_at)
-
- @endif
- |
-
- @yield('detail-information-table')
-
-
-
- @if ($data->description)
-
{{ __('Description') }}
-
-
{{ $data->description }}
- @endif
-
- @if ($data->introduction)
-
{{ __('Introduction') }}
-
-
{{ $data->introduction }}
- @endif
-
- @if ($data->content)
-
{{ __('Content') }}
-
-
{!! $data->content !!}
- @endif
-
- @if ($data->summary)
-
{{ __('Summary') }}
-
-
{!! $data->summary !!}
- @endif
-
-
-
-
-
-
-
-
diff --git a/resources/views/layouts/resource/detail-tables.blade.php b/resources/views/layouts/resource/detail-tables.blade.php
new file mode 100644
index 0000000..addb894
--- /dev/null
+++ b/resources/views/layouts/resource/detail-tables.blade.php
@@ -0,0 +1,45 @@
+@if ($hasTables)
+@foreach ($dataDetail['tables'] as $table)
+
+@endforeach
+@endif
diff --git a/resources/views/layouts/resource/detail-timestamps.blade.php b/resources/views/layouts/resource/detail-timestamps.blade.php
new file mode 100644
index 0000000..326c279
--- /dev/null
+++ b/resources/views/layouts/resource/detail-timestamps.blade.php
@@ -0,0 +1,26 @@
+
+ @if ($data->created_at)
+ -
+ {{ __('Created') }}:
+
+
+ @endif
+ @if ($data->updated_at)
+ -
+ {{ __('Updated') }}:
+
+
+ @endif
+ @if ($data->deleted_at)
+ -
+ {{ __('Deleted') }}:
+
+
+ @endif
+ @if ($data->closed_at)
+ -
+ {{ __('Closed At') }}:
+
+
+ @endif
+
diff --git a/resources/views/layouts/resource/detail.blade.php b/resources/views/layouts/resource/detail.blade.php
index 0d9bb5d..3f84d18 100644
--- a/resources/views/layouts/resource/detail.blade.php
+++ b/resources/views/layouts/resource/detail.blade.php
@@ -28,9 +28,16 @@
$withPrivilege = !empty($meta['info']) && !empty($meta['info']['privilege']) && is_string($meta['info']['privilege']) ? $meta['info']['privilege'] : 'playground';
+$_return_url = old('_return_url');
+
+$routeModule = route($meta['info']['module_route']);
+$routeModel = route($meta['info']['model_route']);
+$routeShow = !$data ? '' : route(sprintf('%1$s.show', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]);
+$routeLock = !$data ? '' : route(sprintf('%1$s.lock', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]);
$routeUnlock = !$data ? '' : route(sprintf('%1$s.unlock', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]);
-$routeDelete = !$data ? '' : route(sprintf('%1$s.destroy', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]);
-$routeEdit = !$data ? '' : route(sprintf('%1$s.edit', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]);
+$routeDelete = !$data ? '' : route(sprintf('%1$s.destroy', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id'), '_return_url' => $_return_url ?: $routeShow]);
+$routeRestore = !$data ? '' : route(sprintf('%1$s.restore', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]);
+$routeEdit = !$data ? '' : route(sprintf('%1$s.edit', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id'), '_return_url' => $_return_url ?: $routeShow]);
$user = \Illuminate\Support\Facades\Auth::user();
@@ -62,16 +69,68 @@
'roles' => ['admin', 'manager'],
])->allowed();
+$withLock = \Playground\Auth\Facades\Can::access($user, [
+ 'allow' => false,
+ 'any' => true,
+ 'privilege' => $withPrivilege . ':lock',
+ 'roles' => ['admin', 'manager'],
+])->allowed();
+
+/**
+ * @var boolean|string $withAccordion
+ */
+$withAccordion = isset($withAccordion) && (is_bool($withAccordion) || is_string($withAccordion)) ? $withAccordion : false;
+
+/**
+ * @var boolean|string $withAccordionFlags
+ */
+$withAccordionFlags = isset($withAccordionFlags) && (is_bool($withAccordionFlags) || is_string($withAccordionFlags)) ? $withAccordionFlags : true;
+
+/**
+ * @var boolean|string $withAccordionTimestamps
+ */
+$withAccordionTimestamps = isset($withAccordionTimestamps) && (is_bool($withAccordionTimestamps) || is_string($withAccordionTimestamps)) ? $withAccordionTimestamps : true;
+
+/**
+ * @var boolean|string $withCard
+ */
+$withCard = isset($withCard) && (is_bool($withCard) || is_string($withCard)) ? $withCard : true;
+
+/**
+ * @var boolean|string $withCardHeader
+ */
+$withCardHeader = isset($withCardHeader) && (is_bool($withCardHeader) || is_string($withCardHeader)) ? $withCardHeader : true;
+
+/**
+ * @var boolean|string $withCardBody
+ */
+$withCardBody = isset($withCardBody) && (is_bool($withCardBody) || is_string($withCardBody)) ? $withCardBody : true;
+
+/**
+ * @var boolean|string $withCardFlags
+ */
+$withCardFlags = isset($withCardFlags) && (is_bool($withCardFlags) || is_string($withCardFlags)) ? $withCardFlags : true;
+
+/**
+ * @var boolean|string $withCardTimestamps
+ */
+$withCardTimestamps = isset($withCardTimestamps) && (is_bool($withCardTimestamps) || is_string($withCardTimestamps)) ? $withCardTimestamps : true;
+
/**
* @var boolean|string $withInfo
*/
$withInfo = isset($withInfo) && (is_bool($withInfo) || is_string($withInfo)) ? $withInfo : true;
/**
- * @var boolean $withInfo
+ * @var boolean $withImage
*/
$withImage = isset($withImage) && is_bool($withImage) ? $withImage : true;
+/**
+ * @var boolean $withTables
+ */
+$withTables = isset($withTables) && is_bool($withTables) ? $withTables : true;
+
/**
* @var boolean $hasTables
*/
@@ -84,97 +143,60 @@
@section('breadcrumbs')
@endsection
@section('content')
-
-
- @if ($withCreate)
-
- @endif
-
- @yield('section-primary')
-
- @if ($withInfo)
- @if (is_string($withInfo))
-
- @include($withInfo)
-
- @else
- @include('playground::layouts.resource.detail-information')
- @endif
- @endif
-
- @yield('section-secondary')
-
- @yield('section-children')
-
- @if ($hasTables)
- @foreach ($dataDetail['tables'] as $table)
-
- @endforeach
- @endif
-
- @yield('section-tables')
-
- @yield('section-tertiary')
-
-
+
+ @yield('section-header')
+
+ @includeWhen($withCard, 'playground::layouts.resource.detail-card')
+
+ @includeWhen($withAccordion, 'playground::layouts.resource.detail-accordion')
+
+ @yield('section-primary')
+
+ @yield('section-secondary')
+
+ @yield('section-children')
+
+ @includeWhen($withTables, 'playground::layouts.resource.detail-tables')
+
+ @yield('section-tables')
+
+ @yield('section-tertiary')
+
+ @yield('section-footer')
+
@endsection
+
+@push('body')
+
+@endpush
diff --git a/resources/views/layouts/resource/form.blade.php b/resources/views/layouts/resource/form.blade.php
index 0e5fcae..e18e676 100644
--- a/resources/views/layouts/resource/form.blade.php
+++ b/resources/views/layouts/resource/form.blade.php
@@ -98,12 +98,23 @@
*/
$model_attribute = $hasMetaInfo && $data && is_string($data->getAttributeValue($meta['info']['model_attribute'])) ? $data->getAttributeValue($meta['info']['model_attribute']) : '';
+$_return_url = old('_return_url');
+
+$routeModule = route($meta['info']['module_route']);
+$routeModel = route($meta['info']['model_route']);
+
+$routeShow = '';
+$routeCreate = route(sprintf('%1$s.create', $meta['info']['model_route']), ['_return_url' => $_return_url]);
+$routeEdit = '';
+
$formTitle = '';
$_methodUrl = '';
$_method = empty($_method) ? '' : $_method;
if ('patch' === $_method) {
$formTitle = sprintf('Editing: %1$s', $model_attribute);
$_methodUrl = route(sprintf('%1$s.patch', $meta['info']['model_route']), $data?->getAttributeValue('id'));
+ $routeShow = route(sprintf('%1$s.show', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id')]);
+ $routeEdit = route(sprintf('%1$s.edit', $meta['info']['model_route']), [$meta['info']['model_slug'] => $data->getAttributeValue('id'), '_return_url' => $_return_url ?: $routeShow]);
} elseif ('post' === $_method) {
$formTitle = sprintf('Create a %1$s', $meta['info']['model_label']);
$_methodUrl = route(sprintf('%1$s.post', $meta['info']['model_route']));
@@ -117,18 +128,42 @@
@section('breadcrumbs')
@@ -145,7 +180,7 @@
@csrf
-
+
@if ('patch' === $_method)
@@ -185,10 +220,15 @@
@else
@endif
diff --git a/resources/views/layouts/resource/index.blade.php b/resources/views/layouts/resource/index.blade.php
index 2d65b54..a408af2 100644
--- a/resources/views/layouts/resource/index.blade.php
+++ b/resources/views/layouts/resource/index.blade.php
@@ -101,6 +101,7 @@
'routeEdit' => sprintf('%1$s.edit', $meta['info']['model_route']),
'routeDelete' => sprintf('%1$s.destroy', $meta['info']['model_route']),
'routeRestore' => sprintf('%1$s.restore', $meta['info']['model_route']),
+ 'routeShow' => sprintf('%1$s.show', $meta['info']['model_route']),
'routeUnlock' => sprintf('%1$s.unlock', $meta['info']['model_route']),
'paginator' => $paginator ?? null,
'privilege' => $withPrivilege,
@@ -117,11 +118,21 @@
@section('breadcrumbs')
@endsection
diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php
index dda1c41..4501ef7 100644
--- a/src/ServiceProvider.php
+++ b/src/ServiceProvider.php
@@ -21,25 +21,40 @@ class ServiceProvider extends AuthServiceProvider
public function boot(): void
{
+ /**
+ * @var array
$config
+ */
$config = config($this->package);
- if (! empty($config)) {
- $this->loadViewsFrom(
- dirname(__DIR__).'/resources/views',
- 'playground'
- );
+ if (! empty($config['load']) && is_array($config['load'])) {
- Blade::componentNamespace('Playground\\Blade\\View\\Components', 'playground');
+ if (! empty($config['load']['translations'])) {
+ $this->loadTranslationsFrom(
+ dirname(__DIR__).'/lang',
+ $this->package
+ );
+ }
+
+ if (! empty($config['load']['views'])) {
+
+ Blade::componentNamespace('Playground\\Blade\\View\\Components', 'playground');
+ $this->loadViewsFrom(
+ dirname(__DIR__).'/resources/views',
+ 'playground'
+ );
+ }
if ($this->app->runningInConsole()) {
// Publish configuration
$this->publishes([
- sprintf('%1$s/config/playground-blade.php', dirname(__DIR__)) => config_path('playground-blade.php'),
+ sprintf('%1$s/config/%2$s.php', dirname(__DIR__), $this->package) => config_path(sprintf('%1$s.php', $this->package)),
], 'playground-config');
$this->publishesAssets();
}
+ }
+ if (! empty($config['about'])) {
$this->about();
}
}
diff --git a/src/View/Components/Forms/ColumnSelect.php b/src/View/Components/Forms/ColumnSelect.php
index 50d9763..993159e 100644
--- a/src/View/Components/Forms/ColumnSelect.php
+++ b/src/View/Components/Forms/ColumnSelect.php
@@ -28,6 +28,10 @@ public function __construct(
public string $key = 'label',
public string $label = '',
public string $pattern = '',
+ /**
+ * @var array>
+ */
+ public array $flags = [],
public bool|string $placeholder = false,
/**
* @var array> $records
diff --git a/src/View/Components/ModelImage.php b/src/View/Components/ModelImage.php
new file mode 100644
index 0000000..cac000d
--- /dev/null
+++ b/src/View/Components/ModelImage.php
@@ -0,0 +1,41 @@
+ $columnMeta
+ */
+ public array $columnMeta = [],
+ /**
+ * @var array $fkModelData
+ */
+ public array $fkModelData = [],
+ public mixed $value = null
+ ) {
+ }
+
+ public function render(): Factory|View
+ {
+ $prefix = config('playground-blade.view');
+
+ return view(sprintf(
+ '%1$scomponents.model.image',
+ is_string($prefix) ? $prefix : ''
+ ));
+ }
+}