3.3 documentation

  1. Registering Routes
  2. Generating URL

Registering Routes

Routing with Orchestra Platform is still based on Laravel routing engine. However we include two base method for registering routes; Foundation::namespaced() and Foundation::group().

Frontend Routing

Anything other than Orchestra Platform administration routes are considered as frontend routing, this includes routing to frontend for app and extensions.

use Illuminate\Routing\Router;

Foundation::group('app', '/', ['namespace' => 'App\Http\Controllers'], function (Router $router) {
    $router->resources('photos', 'PhotoController', ['only' => ['index', 'show']]);
});

The main different is that we now include a namespace and a fallback prefix before providing any attributes for our route group. In this case app is our route namespace and / is the fallback prefix URL if app path is not registered.

The reason namespace is important because using this concept we can set an anchor to the URL via the following:

<a href="{{ handles('app::photos') }}">List Photos</a>

Using ModuleServiceProvider

You can simplify frontend routing by utilizing Orchestra\Foundation\Support\Providers\ModuleServiceProvider.

<?php namespace App\Providers;

use Orchestra\Foundation\Support\Providers\ModuleServiceProvider;

class ModuleServiceProvider extends ModuleServiceProvider
{
    protected $namespace = 'App\Http\Controllers';

    protected $routeGroup = 'app';

    protected $routePrefix = '/';

    protected function loadRoutes()
    {
        $this->afterExtensionLoaded(function () {
            $this->loadFrontendRoutesFrom(app_path('Http/frontend.php'));
        });
    }
}

And under app/Http/frontend.php:

<?php

use Illuminate\Routing\Router;

$router->resources('photos', 'PhotoController', ['only' => ['index', 'show']]);

Backend Routing

You can easily create a new page for Orchestra Platform administration routes by using Foundation::namespaced():

use Illuminate\Routing\Router;

Foundation::namespaced('App\Http\Controllers\Admin', function (Router $router) {
    $router->resource('photos', 'PhotoController');
});

Above code improves the basic Route::group() by adding few things:

  • Set the proper prefix or domain path for Orchestra Platform administration page.
  • Add Orchestra\Foundation\Http\Middleware\UseBackendTheme middleware.
  • Add route group namespace to App\Http\Controllers\Admin.

It's actually an alias of Foundation::group() with additional configuration, above code is actually an equivalent of using Foundation::group() as the following:

use Illuminate\Routing\Router;
use Orchestra\Foundation\Http\Middleware\UseBackendTheme;

Foundation::group(
    'orchestra/foundation',
    'admin',
    ['middleware' => UseBackendTheme::class, 'namespace' => 'App\Http\Controllers\Admin'],
    function (Router $router) {
        $router->resource('photos', 'PhotoController');
    }
);

Using ModuleServiceProvider

You can simplify backend routing by utilizing Orchestra\Foundation\Support\Providers\ModuleServiceProvider.

<?php namespace App\Providers;

use Orchestra\Foundation\Support\Providers\ModuleServiceProvider;

class ModuleServiceProvider extends ModuleServiceProvider
{
    protected $namespace = 'App\Http\Controllers';

    protected $routeGroup = 'app';

    protected $routePrefix = '/';

    protected function loadRoutes()
    {
        $this->loadBackendRoutesFrom(app_path('Http/backend.php'), "{$this->namespace}\Admin");
    }
}

And under app/Http/backend.php:

<?php

use Illuminate\Routing\Router;

$router->resources('photos', 'PhotoController');

Generating URL

In order to make the routing configurable we have merged route(), action() and url() to a single Foundation::handles() method.