Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How does Runway handle front-end routing for Eloquent models


How does Runway handle front-end routing for Eloquent models


Runway, a Statamic addon, provides a powerful way to handle front-end routing for Eloquent models. Here's how it works:

1. Enable front-end routing for your Eloquent models by adding a `route` key to your resource configuration in `config/runway.php`. You can use Antlers syntax for dynamic parts like slugs or dates[1].

php
'route' => '/products/{{ slug }}',

2. Add the `RunwayRoutes` trait to your Eloquent model to enable front-end routing[3].

php
use StatamicRadPack\Runway\Routing\Traits\RunwayRoutes;

class Product extends Model {
    use RunwayRoutes;
}

3. Run `php please runway:rebuild-uris` to build the "URIs cache" that Runway uses to map models to URIs[3].

4. Customize the template and layout used for your model's front-end views by specifying them in the resource configuration[3].

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

5. Access model data in your front-end views, including `created_at`, `updated_at`, and any other model attributes[3].

6. If using Statamic's Static Caching, Runway will automatically invalidate the URI of your models when they are saved. You can also configure additional URIs to be invalidated[3].

Runway uses the `runway_uris` table to efficiently map URIs to Eloquent models. It automatically updates this mapping whenever models are created, updated, or deleted[3].

By leveraging Runway's front-end routing capabilities, you can seamlessly integrate Eloquent models into your Statamic-powered website, providing a consistent user experience and easy management of your application's data.

Citations:
[1] https://statamic.com/addons/rad-pack/runway
[2] https://statamic.com/addons/rad-pack/runway/release-notes
[3] https://runway.duncanmcclean.com/frontend-routing
[4] https://statamic.dev/routing
[5] https://statamic.dev/tips/laravel-nova