Skip to content

Commit

Permalink
Feature: routing prefix (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: ZedoX <75579178+Z3d0X@users.noreply.github.com>
  • Loading branch information
MuhamadSelim and Z3d0X authored Oct 19, 2022
1 parent 8984d4b commit 4708084
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions config/filament-fabricator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
return [
'routing' => [
'enabled' => true,
'prefix' => null // /pages
],

'layouts' => [
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Z3d0X\FilamentFabricator\Facades\FilamentFabricator;

if (config('filament-fabricator.routing.enabled')) {
Route::middleware(SubstituteBindings::class)->group(function () {
Route::middleware(SubstituteBindings::class)->prefix(config('filament-fabricator.routing.prefix', null))->group(function () {
Route::get('/{filamentFabricatorPage?}', function ($filamentFabricatorPage = null) {
// Handle root (home) page
if (blank($filamentFabricatorPage)) {
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public static function form(Form $form): Form
->schema([
Placeholder::make('page_url')
->visible(fn ($record) => filled($record))
->content(fn ($record) => FilamentFabricator::getPageUrlFromId($record?->id, true)),
->content(fn ($record) => config('filament-fabricator.routing.prefix') . FilamentFabricator::getPageUrlFromId($record?->id, true)),

TextInput::make('title')
->label(__('filament-fabricator::page-resource.labels.title'))
->afterStateUpdated(function (Closure $get, Closure $set, ?string $state, ?Model $record) {
if (! $get('is_slug_changed_manually') && filled($state) && blank($record)) {
if (!$get('is_slug_changed_manually') && filled($state) && blank($record)) {
$set('slug', Str::slug($state));
}
})
Expand Down Expand Up @@ -148,7 +148,7 @@ public static function table(Table $table): Table
EditAction::make(),
Action::make('visit')
->label(__('filament-fabricator::page-resource.actions.visit'))
->url(fn ($record) => FilamentFabricator::getPageUrlFromId($record->id, true))
->url(fn ($record) => config('filament-fabricator.routing.prefix') . FilamentFabricator::getPageUrlFromId($record->id, true))
->icon('heroicon-o-external-link')
->openUrlInNewTab()
->color('success')
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/PageResource/Pages/EditPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function getActions(): array
Actions\DeleteAction::make(),
Action::make('visit')
->label(__('filament-fabricator::page-resource.actions.visit'))
->url(fn () => FilamentFabricator::getPageUrlFromId($this->record->id, true))
->url(fn () => config('filament-fabricator.routing.prefix') . FilamentFabricator::getPageUrlFromId($this->record->id, true))
->icon('heroicon-o-external-link')
->openUrlInNewTab()
->color('success')
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/PageResource/Pages/ViewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function getActions(): array
Actions\EditAction::make(),
Action::make('visit')
->label(__('filament-fabricator::page-resource.actions.visit'))
->url(fn () => FilamentFabricator::getPageUrlFromId($this->record->id, true))
->url(fn () => config('filament-fabricator.routing.prefix') . FilamentFabricator::getPageUrlFromId($this->record->id, true))
->icon('heroicon-o-external-link')
->openUrlInNewTab()
->color('success')
Expand Down

0 comments on commit 4708084

Please sign in to comment.