Skip to content

Module Routing

Custom modules can define their own routes in the routes.php file. Evolve will automatically load these routes when the module is registered.

Important

If your service provider extends the ModuleServiceProvider, your module routes will be expected in src/Http/routes.php.

Admin routes

Evolve provides a evolveModule macro on the Route facade to group module routes:

php
Route::evolveModule('blog', function () {
    Route::resource('/post', PostController::class);
    // ...

Routes wrapped with this macro will have URLs prefixed with evolve/[module-name]/* and use the web and auth middlewares. Also the route names will be prefixed with [module-name].*

Routeable models

You can dynamically make your models routeable by implementing the Routeable interface and using the HasFrontendRoute trait:

php
use Illuminate\Database\Eloquent\Model;
use Racerfish\Evolve\Contracts\Routeable;
use Racerfish\Evolve\Concerns\HasFrontendRoute;

class Post extends Model implements Routeable
{
    use HasFrontendRoute;

When new entities of this type are stored in the database, Evolve will also create a slug based on the title or name property from your model.

Example: A new blog post with the title "Lorem Ipsum" creates a new route de/lorem-ipsum. (Translated models are always prefixed with the correct locale)

Customizing the route generation

You can override following functions from the HasFrontendRoute trait to customize the page title and slug for your model:

  • getPageTitle
  • getRoutePath

Defining model visibility

Sometimes you need to define the visibility of models based on some active/inactive, published/unpublished states. You can easily make this by defining a public query builder scope on your model.

Models which can't be queried with the public scope will return a 404 Not Found for guest users.

php
public function scopePublic(Builder $query, bool $withHidden = false)
{
    return $query->where('is_active', true);
}

Use the $withHidden flag to define visibiliy for hidden but not private access.

Other frontend routes

There's no specific way to define other custom frontend routes, just be sure to always wrap them into the web middleware.