Skip to content

Commit 034a61b

Browse files
committed
permalink generation
1 parent a8a8e6f commit 034a61b

File tree

4 files changed

+101
-76
lines changed

4 files changed

+101
-76
lines changed

packages/category/src/Moox/Entities/Categories/Category/CategoryResource.php

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public static function form(Schema $schema): Schema
5858
TitleWithSlugInput::make(
5959
fieldTitle: 'title',
6060
fieldSlug: 'slug',
61+
fieldPermalink: 'permalink',
62+
urlPathEntityType: 'categories',
6163
slugRuleUniqueParameters: [
6264
'modifyRuleUsing' => function (Unique $rule, $record, $livewire) {
6365
$locale = $livewire->lang;
@@ -86,13 +88,13 @@ public static function form(Schema $schema): Schema
8688
relationship: 'parent',
8789
titleAttribute: 'title',
8890
parentAttribute: 'parent_id',
89-
modifyQueryUsing: fn (Builder $query, $get) => $query->where('id', '!=', $get('id'))
91+
modifyQueryUsing: fn(Builder $query, $get) => $query->where('id', '!=', $get('id'))
9092
)
9193
->label('Parent Category')
9294
->searchable()
93-
->disabledOptions(fn ($get): array => [$get('id')])
95+
->disabledOptions(fn($get): array => [$get('id')])
9496
->enableBranchNode()
95-
->visible(fn () => Category::count() > 0),
97+
->visible(fn() => Category::count() > 0),
9698
])
9799
->columnSpan(2),
98100
Grid::make()
@@ -107,16 +109,16 @@ public static function form(Schema $schema): Schema
107109
TextInput::make('weight')->numeric(),
108110
TextInput::make('count')
109111
->disabled()
110-
->visible(fn ($livewire, $record): bool => ($record && $livewire instanceof EditCategory) || ($record && $livewire instanceof ViewCategory)),
112+
->visible(fn($livewire, $record): bool => ($record && $livewire instanceof EditCategory) || ($record && $livewire instanceof ViewCategory)),
111113
DateTimePicker::make('created_at')
112114
->disabled()
113-
->visible(fn ($livewire, $record): bool => ($record && $livewire instanceof EditCategory) || ($record && $livewire instanceof ViewCategory)),
115+
->visible(fn($livewire, $record): bool => ($record && $livewire instanceof EditCategory) || ($record && $livewire instanceof ViewCategory)),
114116
DateTimePicker::make('updated_at')
115117
->disabled()
116-
->visible(fn ($livewire, $record): bool => ($record && $livewire instanceof EditCategory) || ($record && $livewire instanceof ViewCategory)),
118+
->visible(fn($livewire, $record): bool => ($record && $livewire instanceof EditCategory) || ($record && $livewire instanceof ViewCategory)),
117119
DateTimePicker::make('deleted_at')
118120
->disabled()
119-
->visible(fn ($livewire, $record): bool => $record && $record->trashed() && $livewire instanceof ViewCategory),
121+
->visible(fn($livewire, $record): bool => $record && $record->trashed() && $livewire instanceof ViewCategory),
120122
]),
121123
])
122124
->columnSpan(1)
@@ -133,7 +135,7 @@ public static function table(Table $table): Table
133135
$currentTab = static::getCurrentTab();
134136

135137
return $table
136-
->query(fn (): Builder => static::getEloquentQuery())
138+
->query(fn(): Builder => static::getEloquentQuery())
137139
->defaultSort('_lft', 'asc')
138140
->columns([
139141
TextColumn::make('id')->sortable(),
@@ -170,7 +172,7 @@ public static function table(Table $table): Table
170172
}),
171173
TextColumn::make('level')
172174
->label(__('category::fields.level'))
173-
->getStateUsing(fn (Category $record): int => $record->ancestors->count() + 1)
175+
->getStateUsing(fn(Category $record): int => $record->ancestors->count() + 1)
174176
->sortable()
175177
->toggleable(isToggledHiddenByDefault: true),
176178
TextColumn::make('children_count')
@@ -212,16 +214,16 @@ public static function table(Table $table): Table
212214
->defaultSort('updated_at', 'desc')
213215
->recordActions([
214216
ViewAction::make(),
215-
EditAction::make()->hidden(fn (): bool => in_array(static::getCurrentTab(), ['trash', 'deleted'])),
217+
EditAction::make()->hidden(fn(): bool => in_array(static::getCurrentTab(), ['trash', 'deleted'])),
216218
])
217219
->toolbarActions([
218-
DeleteBulkAction::make()->hidden(fn (): bool => in_array($currentTab, ['trash', 'deleted'])),
219-
RestoreBulkAction::make()->visible(fn (): bool => in_array($currentTab, ['trash', 'deleted'])),
220+
DeleteBulkAction::make()->hidden(fn(): bool => in_array($currentTab, ['trash', 'deleted'])),
221+
RestoreBulkAction::make()->visible(fn(): bool => in_array($currentTab, ['trash', 'deleted'])),
220222
])
221223
->filters([
222224
SelectFilter::make('parent_id')
223225
->label(__('category::fields.parent'))
224-
->relationship('parent', 'title', fn ($query) => $query->has('children'))
226+
->relationship('parent', 'title', fn($query) => $query->has('children'))
225227
->searchable(),
226228
SelectFilter::make('children_count')
227229
->label(__('category::fields.children_count'))
@@ -231,7 +233,7 @@ public static function table(Table $table): Table
231233
'6-10' => '6-10',
232234
'10+' => '10+',
233235
])
234-
->query(fn (Builder $query, array $data) => $query->when($data['value'], function ($query, $option) {
236+
->query(fn(Builder $query, array $data) => $query->when($data['value'], function ($query, $option) {
235237
switch ($option) {
236238
case '0':
237239
return $query->doesntHave('children');
@@ -245,8 +247,8 @@ public static function table(Table $table): Table
245247
})),
246248
SelectFilter::make('depth')
247249
->label(__('category::fields.level'))
248-
->options(fn (): array => array_combine(range(1, 5), range(1, 5)))
249-
->query(fn (Builder $query, array $data) => $query->when($data['value'], function ($query, $depth): void {
250+
->options(fn(): array => array_combine(range(1, 5), range(1, 5)))
251+
->query(fn(Builder $query, array $data) => $query->when($data['value'], function ($query, $depth): void {
250252
$query->whereIn('id', function ($subquery) use ($depth): void {
251253
$subquery->select('id')
252254
->from('categories as c')
@@ -257,16 +259,16 @@ public static function table(Table $table): Table
257259
->defaultSort('id', 'asc')
258260
->recordActions([
259261
ViewAction::make(),
260-
EditAction::make()->hidden(fn (): bool => in_array(static::getCurrentTab(), ['trash', 'deleted'])),
262+
EditAction::make()->hidden(fn(): bool => in_array(static::getCurrentTab(), ['trash', 'deleted'])),
261263
])
262264
->toolbarActions([
263-
DeleteBulkAction::make()->hidden(fn (): bool => in_array($currentTab, ['trash', 'deleted'])),
264-
RestoreBulkAction::make()->visible(fn (): bool => in_array($currentTab, ['trash', 'deleted'])),
265+
DeleteBulkAction::make()->hidden(fn(): bool => in_array($currentTab, ['trash', 'deleted'])),
266+
RestoreBulkAction::make()->visible(fn(): bool => in_array($currentTab, ['trash', 'deleted'])),
265267
])
266268
->filters([
267269
SelectFilter::make('parent_id')
268270
->label(__('category::fields.parent'))
269-
->relationship('parent', 'title', fn ($query) => $query->has('children'))
271+
->relationship('parent', 'title', fn($query) => $query->has('children'))
270272
->searchable(),
271273
SelectFilter::make('children_count')
272274
->label(__('category::fields.children_count'))
@@ -276,7 +278,7 @@ public static function table(Table $table): Table
276278
'6-10' => '6-10',
277279
'10+' => '10+',
278280
])
279-
->query(fn (Builder $query, array $data) => $query->when($data['value'], function ($query, $option) {
281+
->query(fn(Builder $query, array $data) => $query->when($data['value'], function ($query, $option) {
280282
switch ($option) {
281283
case '0':
282284
return $query->doesntHave('children');
@@ -290,8 +292,8 @@ public static function table(Table $table): Table
290292
})),
291293
SelectFilter::make('depth')
292294
->label(__('category::fields.level'))
293-
->options(fn (): array => array_combine(range(1, 5), range(1, 5)))
294-
->query(fn (Builder $query, array $data) => $query->when($data['value'], function ($query, $depth): void {
295+
->options(fn(): array => array_combine(range(1, 5), range(1, 5)))
296+
->query(fn(Builder $query, array $data) => $query->when($data['value'], function ($query, $depth): void {
295297
$query->whereIn('id', function ($subquery) use ($depth): void {
296298
$subquery->select('id')
297299
->from('categories as c')

packages/draft/src/Moox/Entities/Drafts/Draft/DraftResource.php

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public static function form(Schema $form): Schema
8181
TitleWithSlugInput::make(
8282
fieldTitle: 'title',
8383
fieldSlug: 'slug',
84+
fieldPermalink: 'permalink',
85+
urlPathEntityType: 'drafts',
8486
slugRuleUniqueParameters: [
8587
'modifyRuleUsing' => function (Unique $rule, $record, $livewire) {
8688
$locale = $livewire->lang;
@@ -138,13 +140,13 @@ public static function form(Schema $form): Schema
138140
DateTimePicker::make('to_publish_at')
139141
->label('To publish at')
140142
->placeholder(__('core::core.to_publish_at'))
141-
->hidden(fn ($get) => $get('status') !== 'scheduled')
142-
->dehydrateStateUsing(fn ($state, $get) => $get('status') === 'scheduled' ? $state : null),
143+
->hidden(fn($get) => $get('status') !== 'scheduled')
144+
->dehydrateStateUsing(fn($state, $get) => $get('status') === 'scheduled' ? $state : null),
143145
DateTimePicker::make('to_unpublish_at')
144146
->label('To unpublish at')
145147
->placeholder(__('core::core.to_unpublish_at'))
146-
->hidden(fn ($get) => ! in_array($get('status'), ['scheduled', 'published']))
147-
->dehydrateStateUsing(fn ($state, $get) => in_array($get('status'), ['scheduled', 'published']) ? $state : null),
148+
->hidden(fn($get) => !in_array($get('status'), ['scheduled', 'published']))
149+
->dehydrateStateUsing(fn($state, $get) => in_array($get('status'), ['scheduled', 'published']) ? $state : null),
148150
]),
149151
Section::make('')
150152
->schema($taxonomyFields),
@@ -162,41 +164,41 @@ public static function form(Schema $form): Schema
162164
->schema([
163165
CopyableField::make('id')
164166
->label('ID')
165-
->defaultValue(fn ($record): string => $record->id ?? ''),
167+
->defaultValue(fn($record): string => $record->id ?? ''),
166168
CopyableField::make('uuid')
167169
->label('UUID')
168-
->defaultValue(fn ($record): string => $record->uuid ?? ''),
170+
->defaultValue(fn($record): string => $record->uuid ?? ''),
169171
CopyableField::make('ulid')
170172
->label('ULID')
171-
->defaultValue(fn ($record): string => $record->ulid ?? ''),
173+
->defaultValue(fn($record): string => $record->ulid ?? ''),
172174
Section::make('')
173175
->schema([
174176
Placeholder::make('created_at')
175177
->label('Created')
176-
->content(fn ($record): string => $record->created_at ?
177-
$record->created_at.' - '.$record->created_at->diffForHumans() : '')
178+
->content(fn($record): string => $record->created_at ?
179+
$record->created_at . ' - ' . $record->created_at->diffForHumans() : '')
178180
->extraAttributes(['class' => 'font-mono']),
179181
Placeholder::make('updated_at')
180182
->label('Last Updated')
181-
->content(fn ($record): string => $record->updated_at ?
182-
$record->updated_at.' - '.$record->updated_at->diffForHumans() : '')
183+
->content(fn($record): string => $record->updated_at ?
184+
$record->updated_at . ' - ' . $record->updated_at->diffForHumans() : '')
183185
->extraAttributes(['class' => 'font-mono']),
184186
Placeholder::make('published_at')
185187
->label('Published')
186-
->content(fn ($record): string => $record->published_at ?
187-
$record->published_at.' - '.$record->published_at->diffForHumans().
188-
($record->published_by_id ? ' by '.$record->published_by_id : '') : '')
188+
->content(fn($record): string => $record->published_at ?
189+
$record->published_at . ' - ' . $record->published_at->diffForHumans() .
190+
($record->published_by_id ? ' by ' . $record->published_by_id : '') : '')
189191
->extraAttributes(['class' => 'font-mono'])
190-
->hidden(fn ($record) => ! $record->published_at),
192+
->hidden(fn($record) => !$record->published_at),
191193
Placeholder::make('to_unpublish_at')
192194
->label('To Unpublish')
193-
->content(fn ($record): string => $record->to_unpublish_at ?
194-
$record->to_unpublish_at.' - '.$record->to_unpublish_at->diffForHumans() : '')
195+
->content(fn($record): string => $record->to_unpublish_at ?
196+
$record->to_unpublish_at . ' - ' . $record->to_unpublish_at->diffForHumans() : '')
195197
->extraAttributes(['class' => 'font-mono'])
196-
->hidden(fn ($record) => ! $record->to_unpublish_at),
198+
->hidden(fn($record) => !$record->to_unpublish_at),
197199
]),
198200
])
199-
->hidden(fn ($record) => $record === null),
201+
->hidden(fn($record) => $record === null),
200202
])
201203
->columnSpan(1)
202204
->columns(1),
@@ -296,32 +298,32 @@ public static function table(Table $table): Table
296298
->schema([
297299
TextInput::make('title')
298300
->label('Title')
299-
->placeholder(__('core::core.filter').' Title'),
301+
->placeholder(__('core::core.filter') . ' Title'),
300302
])
301303
->query(function (Builder $query, array $data): Builder {
302304
return $query->when(
303305
$data['title'],
304-
fn (Builder $query, $value): Builder => $query->where('title', 'like', "%{$value}%"),
306+
fn(Builder $query, $value): Builder => $query->where('title', 'like', "%{$value}%"),
305307
);
306308
})
307309
->indicateUsing(function (array $data): ?string {
308-
if (! $data['title']) {
310+
if (!$data['title']) {
309311
return null;
310312
}
311313

312-
return 'Title: '.$data['title'];
314+
return 'Title: ' . $data['title'];
313315
}),
314316
SelectFilter::make('status')
315317
->label('Status')
316-
->placeholder(__('core::core.filter').' Status')
318+
->placeholder(__('core::core.filter') . ' Status')
317319
->options(['Probably' => 'Probably', 'Never' => 'Never', 'Done' => 'Done', 'Maybe' => 'Maybe']),
318320
SelectFilter::make('type')
319321
->label('Type')
320-
->placeholder(__('core::core.filter').' Type')
322+
->placeholder(__('core::core.filter') . ' Type')
321323
->options(['Post' => 'Post', 'Page' => 'Page']),
322324
SelectFilter::make('section')
323325
->label('Section')
324-
->placeholder(__('core::core.filter').' Section')
326+
->placeholder(__('core::core.filter') . ' Section')
325327
->options(['Header' => 'Header', 'Main' => 'Main', 'Footer' => 'Footer']),
326328
]);
327329
}

0 commit comments

Comments
 (0)