I would like to create a URL system like Notion where you can change the page title and be redirected to the right page from the ID present in the slug. This could fix SEO problems and some issues when the user change the title of a page.
The URL could be something like that https://mydomain.com/title-of-the-page-[$page unique ID]
I think the router part is not too complicated, my problem is for the page creation and the renaming of a page with hooks.
With the hooks, page.create:after and page.changeTitle:after I update the slug with the page unique ID but this throw an error of redirection in the panel. I canβt find any solution to redirect to the updated URL.
Unfortunately, it is not possible to redirect from a hook yet. While you could circumvent the page.create:after issue with using a page model, this wonβt help for the changeTitle stuff.
Have you thought about overriding the url method in a page model to return the scheme you are seeking for? This way you wouldnβt have to actually rename any pages and only have to set up routes to display the correct pages?
class NotionPage extends Page
{
public function url($options = null): string
{
$url = $this->parent()->url() . '/' . $this->slug() . '-' . $this->someIdMethod();
return Url::to($url, $options);
}
}
No, I didnβt retry.
In fact, I think it could be overkill and even not so good for performances.
At the end I think that i was looking for a unique ID generator more than this. And then I saw that Immutable IDs for pages is on the roadmap
For the moment, I could use this plugin to create page with unique ID.