Created
March 3, 2023 13:45
-
-
Save awcodes/530c65089de850ecc15deba577a335f0 to your computer and use it in GitHub Desktop.
Camya Title With Slug Dynamic urlPath
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function show(Request $request) | |
{ | |
$slug = Str::of($request->getPathInfo())->rtrim('/')->afterLast('/'); | |
$page = Page::where('slug', $slug)->isPublished()->firstOrFail(); | |
if ($page->front_page) { | |
return redirect()->to(route('welcome')); | |
} | |
return view('page', [ | |
'page' => $page, | |
]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TitleWithSlugInput::make( | |
fieldTitle: 'title', | |
fieldSlug: 'slug', | |
urlPath: function(callable $get) { | |
return $get('parent') ? '/' . $get('parent') . '/' : '/'; | |
}, | |
slugRules: [] | |
) | |
Select::make('parent') | |
->label('Parent page') | |
->reactive() | |
->searchable() | |
->options(fn() => Page::all()->pluck('title', 'slug')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::fallback([PageController::class, 'show']) | |
->name('pages.show'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment