Skip to content

Instantly share code, notes, and snippets.

@awcodes
Created March 3, 2023 13:45
Show Gist options
  • Save awcodes/530c65089de850ecc15deba577a335f0 to your computer and use it in GitHub Desktop.
Save awcodes/530c65089de850ecc15deba577a335f0 to your computer and use it in GitHub Desktop.
Camya Title With Slug Dynamic urlPath
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,
]);
}
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'))
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