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.
Before getting started, ensure you’ve run
php artisan migrate
. Runway comes with arunway_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 DoubleThreeDigital\Runway\Routing\Traits\RunwayRoutes; class Product extends Model{ use RunwayRoutes;
Last but not least, run php please runway:rebuild-uris
. This command will essentially loop through all of your models, compile the Antlers URIs, and save it to the database for reference later.
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',
Instead your show/detail view of your model, you’ll have access to a bunch of variables:
created_at
, updated_at
.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/*', ], ], ], ], ],