Routers

Introduction

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:

echo "articles/{$article->category->slug}/view/{$article->slug}";
{{ url('articles/' ~ category.slug ~ '/view/' ~ article.slug) }}

You can rely on entry routing to simply do this:

$article->route('view');
{{ article.route('view') }}

Basic Usage

To get started with entry routing you must first define your routes with a specific naming pattern.

We'll use an AddonServiceProvider for routing in this example.

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

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 the Streams Platform will lookup what addon the model belongs to and find use it's stream slug and action to return the route path.

More Examples

$article->route('view');

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

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

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

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