I did exactly the thing you want to do.
create a file called event.php in site/models
paste in this code:
<?php
// Learned this from https://forum.getkirby.com/t/auto-append-to-url-appendix/19722
// on August 28, 2023.
// Found it googling 'kirby cms append number to slug'.
// Yay! Page models FTW!!!!!
// For a content file called 'event.txt'
// In general the class name is {{ShowFileName}}Page
use Kirby\Cms\Page;
use Kirby\Toolkit\Str;
class EventPage extends Page
{
// all methods of the Page class are inherited and can be overridden here now.
public static function create(array $props): Page
{
// $props['slug'] = Str::slug('Hello World'); ///// zu Testzwecken :)
$page = new Page($props);
if ( kirby()->page( $page->id() ) ) {
$props['slug'] = $props['slug'] . '-' . Str::random(16);
}
return parent::create($props);
}
}
I left my comments in there to remember like in a year or so … if I ever have to revise this … what I have done.
Check out the link in the comment (Auto-append to URL-Appendix)
What this does: It adds a random string of 16 characters to the URL appendix. That way it is very unlikely that two slugs are ever the same.
Hope this works for you.
If you need assistance in hiding the URL appendix in the panel (in case that’s something you want to do) let us know.