CMS page get url with parameters

For a model, where a page should be selected, I want to check if the URL contains :token in beforeValidate, how can I achieve that?

When I do:

dd(Page::url($this->cms_page));

Where $this->cms_page is:

Page::getNameList();

I get an url with default as my parameter, e.g. /page/default, but the name of my parameter is token, implemented like this:

url = "/page-name/:token"

/page-name/default, I suspect the page was called without any token. Ex the url called was /page-name/

The thing is that for a newsletter plugin, I want to check if in my newsletter settings the chosen unsubscribe CMS page has the parameter ‘:token’. This parameter is then later used to create a link to that page, where a component should be placed.

I would like to make it as user friendly as possible, so if somebody forgot to add ‘:token’, I show a application error.

Can I make a HTTP request to my own page and then check?

if you see default, can’t this mean the token wasn’t supplied and you display the error?

I found a solution for this.

If the URL is created without parameters, there will be a ‘default’ string added. e.g.:

dd(Page::url($this->newsletter_unsubscribe_cms_page)); // https://example.com/newsletter-unsubscribe/default

With URL creation the parameters can be added and then tested if string contains these parameters. e.g.:

$newsletterUnsubscribeCmsPage = Page::url($this->newsletter_unsubscribe_cms_page, ['token' => 'token']);
if (strpos($newsletterUnsubscribeCmsPage, 'token') === false) {
    throw new \ApplicationException('The URL of your newsletter unsubscribe page needs to contain "/:token" at the end of the URL.');
}