Skip to content

IsHostable ​

Namespace: Unusualify\Modularous\Entities\Traits\IsHostable

Extends HasSlug and Core\ModelHelpers to support multi-level hostable slug routing. Traverses BelongsTo and HasMany relationship chains to build full slug paths including all ancestor segments. Useful for nested page hierarchies where each level has its own slug.


Dependencies ​

Automatically composes:

  • HasSlug — slug storage and route binding
  • Core\ModelHelpers — definedRelations introspection

Properties ​

PropertyTypeDefaultDescription
$hostableColumnstring'url'Column name that stores the hostable URL segment

Methods ​

MethodSignatureDescription
hostables(): Collection (static)Returns all hostable, published models (applies hostable + published scopes)
getHostableColumn(): stringReturns the column name for the hostable URL
hostableRouteArguments(): arrayBuilds the full route parameter array by traversing parent BelongsTo relationships — e.g. ['parent' => 'about-us', 'page' => 'team']
hostableParents(): arrayReturns parent model instances that also use IsHostable
hostableParentRecords(): arrayReturns the actual parent model records
hostableChilds(): arrayReturns child model classes that use IsHostable via HasMany
hostableChildRouteParameters(): arrayReturns child route parameter placeholders
hostableRouteBindingParameter(): string (static)Returns the route parameter placeholder for this model (e.g. {page})

Scopes ​

ScopeDescription
scopeHostable($query)Records with a non-null hostable column and no parent hostable (top-level)
scopeNotParentHostable($query)Records where the parent model has no hostable URL

Usage ​

php
use Unusualify\Modularous\Entities\Traits\IsHostable;

class Page extends Model
{
    use IsHostable;

    public function parent(): BelongsTo
    {
        return $this->belongsTo(Page::class);
    }

    public function children(): HasMany
    {
        return $this->hasMany(Page::class, 'parent_id');
    }
}

// Route generation — builds full slug path
$page->hostableRouteArguments();
// ['parent' => 'about-us', 'page' => 'team']

// Query
Page::hostable()->get();
Page::notParentHostable()->get();

// All published hostable pages
Page::hostables();

Route binding

Because IsHostable composes HasSlug, route model binding works by slug automatically. Define your routes with the model's route parameter placeholder:

php
Route::get('/{page}', PageController::class);
// or for nested:
Route::get('/{parent}/{page}', PageController::class);