Front-end Routing

Front-end routing is honestly my favourite feature in Runway. It lets you setup front-end routes for your Eloquent models - behind the scenes, it works pretty much the exact same way as it does for entries.

Enabling

Before getting started, ensure you’ve run php artisan migrate. Runway comes with a runway_uris table which will be used to store all of the front-end URIs.

First things first, add a route key to your resource config, with the URI structure you want to use. Feel free to use Antlers in there for anything dynamic, like a slug or a date.

// config/runway.php
 
'route' => '/products/{{ slug }}',

Next, add the RunwayRoutes trait to your Eloquent model.

// app/Models/Product.php
 
use StatamicRadPack\Runway\Routing\Traits\RunwayRoutes;
 
class Product extends Model
{
use RunwayRoutes;

If you have any existing models, make sure you run php please runway:rebuild-uris to build the "URIs cache" Runway uses to map models to URIs.

Customising the template/layout used

Runway will assume you want to use the default template and the layout layout for resources.

However, most of the time, you’ll want to change this. To change it, just specify what you want to change them to.

// config/runway.php
 
'template' => 'products.index',
'layout' => 'layouts.shop',

Available variables

Instead your show/detail view of your model, you’ll have access to a bunch of variables:

  • All fields configured in your blueprint (with augmentation of course)
  • Any fields not in your blueprint but configured in your model, like created_at, updated_at.
  • Any other variables provided by the Cascade

Static Caching Invalidation

If you're taking advantage of Statamic's Static Caching functionality, Runway will automatically invalidate the URI of your models on save.

You may also configure additional URIs to be invalidated on save.

// config/statamic/static_caching.php
 
'invalidation' => [
 
'class' => null,
 
'rules' => [
'runway' => [
'product' => [
'urls' => [
'/products',
'/products/*',
],
],
],
],
 
],

URI Cache

Since Runway allows you to define your routes using Antlers, much like collections, Runway needs to index all the possible URIs so it can efficiently find the related Eloquent model.

Runway uses the runway_uris table to do this. Unless disabled, your application will have a runway_uris table, which is responsible for mapping URIs to Eloquent models.

Anytime you create, update or delete an Eloquent model, Runway will update its mappings in the runway_uris table.

Building the URI Cache

When configuring front-end routing in an application with existing models, you should run the php please runway:rebuild-uris command to build the Runway's "URI Cache".

If you wish to limit the models being "cached" by the runway:rebuild-uris command, you may add the runwayRoutes query scope to your model:

class Product extends Model
{
public function scopeRunwayRoutes($query)
{
return $query->where('is_public', true);
}
}

Customizing the table name

By default, Runway will use the runway_uris table to store the "URI Cache". If you wish to change the name of the table, you may do so in the runway.php configuration file:

/*
|--------------------------------------------------------------------------
| Runway URIs Table
|--------------------------------------------------------------------------
|
| When using Runway's front-end routing functionality, Runway will store model
| URIs in a table to enable easy "URI -> model" lookups. If needed, you can
| customize the table name here.
|
*/
 
'uris_table' => 'runway_uris',