Runway Logo

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.

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

Next, add the RunwayRoutes trait to your Eloquent model.

1// app/Models/Product.php
2 
3use DoubleThreeDigital\Runway\Routing\Traits\RunwayRoutes;
4 
5class Product extends Model
6{
7 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.

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.

1// config/runway.php
2 
3'template' => 'products.index',
4'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