Bishwas-py What you need is a custom extension for a slug driver. Bascially you'll want a file with the following:
namespace Your\Extension\Namespace;
use Flarum\Database\AbstractModel;
use Flarum\Http\SlugDriverInterface;
use Flarum\User\User;
class IdSlugDriver implements SlugDriverInterface
{
/**
* @var DiscussionRepository
*/
protected $discussions;
public function __construct(DiscussionRepository $discussions)
{
$this->discussions = $discussions;
}
public function toSlug(AbstractModel $instance): string
{
return $instance->id;
}
public function fromSlug(string $slug, User $actor): AbstractModel
{
return $this->discussions->findOrFail($slug, $actor);
}
}
And then in your extend.php file you'd put the following:
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
use Flarum\Extend;
use Your\Extension\Namespace\IdSlugDriver;
use Flarum\Discussion;
return [
(new Extend\ModelUrl(Discussion::class))->addSlugDriver('idDriver', IdSlugDriver::class),
];
The end result will be the URLs being:
domain.tld/d/{id}
As a reminder, you'll need to do some autoloading and stuff with composer. Our extension docs has some documentation on that.