Entry Routers

Entry routers assist in binding named routes to stream entries. This makes it much easier to override routing by simply defining another route with the same name.

The basic idea is as that instead of something like this in your code:

{{ url('articles/' ~ category.slug ~ '/view/' ~ article.slug) }}

You can rely on entry routing to simply do this:

{{ article.route('view') }}

And via API this would look like:

$article->route('view');

Basic Usage

To get started with entry routing you must first define your routes with a specific naming pattern. Note this is not referring to the path but the route name. We'll use an AddonServiceProvider routing example:

protected $routes = [
    "posts/{slug}"                                              => [
        'as'   => 'anomaly.module.posts::posts.view',
        'uses' => 'Anomaly\PostsModule\Http\Controller\[email protected]',
    ],
];

Note the above route is named anomaly.module.posts::posts.view. This can be broken down into the addons namespace, then the entry's stream slug, and lastly the route action.

{namespace}::{stream}.{action}

By calling route($action) on an entry model Pyro will lookup what addon the model belongs to and find use it's stream slug and action to return the route path.

EntryRouter::make()

The make method returns the entry model's matching route. The name variable can be simply an action or the stream slug and action of another named route within the same addon.

The entry's route method directly wraps make hence $entry->route($action).

Returns: string or null
Arguments
Key Required Type Default Description
$route true string none The route name. Can be simply `action` if route is for the calling model or `stream.action` if route is in calling model's same addon.
$parameters false array none Query string parameters appended to the route.
Example
$article->route('view');

$article->route('categories.index');

// Equivalent long syntax.
$article->getRouter()->make('view');

$article->getRouter()->make('categories.index');
Twig
{{ article.route('view') }}

{{ article.route('categories.index') }}