Skip to content

Generics Overview ​

Generics are cross-cutting utilities and patterns that any module can use. Unlike Module Features (which follow the Entity + Repository + Hydrate triple pattern), generics are lightweight traits and conventions applied wherever they're useful — controllers, arrays, route configs, models.

At a Glance ​

GenericLayerSolvesEntry point
AllowableController traitRole-based filtering of arrays / collections (menus, actions, widgets)use Allowable + allowedRoles key
Responsive VisibilityController traitShow/hide array items per Vuetify breakpointuse ResponsiveVisibility + responsive key
File Storage with FilepondModel trait + inputOne-to-many polymorphic file uploads via FilePonduse HasFileponds + type: filepond
RelationshipsCLI + runtimeEloquent relationship generation and conventions--relationships on make:model / make:route

Decision Guide ​

Need to filter a list by user role? → Allowable

Need to hide menu items on mobile? → Responsive Visibility

Need users to upload files (avatar, attachments)? → File Storage with Filepond

Defining a new module and its relations? → Relationships

Need the full feature triple (Entity + Repository + Hydrate)? → Check Module Features instead.


Quick Examples ​

Allowable — Filter by Role ​

php
use Unusualify\Modularous\Traits\Allowable;

class NavigationController extends Controller
{
    use Allowable;

    public function items()
    {
        return $this->getAllowableItems([
            ['title' => 'Home', 'route' => 'home'],
            ['title' => 'Admin', 'route' => 'admin', 'allowedRoles' => ['admin']],
        ]);
    }
}

Items without allowedRoles are public. See Allowable for closures, guards, and custom search keys.


Responsive Visibility — Breakpoint Control ​

php
use Unusualify\Modularous\Traits\ResponsiveVisibility;

class MenuController extends Controller
{
    use ResponsiveVisibility;

    public function items()
    {
        return $this->getResponsiveItems([
            ['title' => 'Desktop Search', 'responsive' => ['hideBelow' => 'md']],
            ['title' => 'Mobile Menu',    'responsive' => ['hideAbove' => 'md']],
        ]);
    }
}

Applies Vuetify d-{breakpoint}-* classes. See Responsive Visibility for all modifiers (hideOn, showOn, hideBelow, hideAbove, breakpoints).


Filepond — Upload in Three Lines ​

Model:

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

class Ticket extends Model
{
    use HasFileponds;
}

Route config:

php
'inputs' => [
    ['type' => 'filepond', 'name' => 'attachments', 'max' => 5],
]

Repository:

php
use Unusualify\Modularous\Repositories\Traits\FilepondsTrait;

class TicketRepository extends Repository
{
    use FilepondsTrait;
}

See File Storage with Filepond for storage mechanics and Files and Media for the full triple pattern.


Relationships — Define at Generation Time ​

bash
# Model-level (adds method to parent model)
php artisan modularous:make:model Package Billing \
  --relationships="belongsToMany:Feature"

# Route-level (creates pivot + migration + reverse relation)
php artisan modularous:make:route Billing packages \
  --relationships="Feature:belongsToMany,position:integer:unsigned:index"

See Relationships for full grammar, field types, and modifiers.


Composing Generics ​

Generics are independent, so you can stack them. The most common combo is Allowable + ResponsiveVisibility on the same menu:

php
use Unusualify\Modularous\Traits\{Allowable, ResponsiveVisibility};

class MenuController extends Controller
{
    use Allowable, ResponsiveVisibility;

    public function items()
    {
        $items = [
            [
                'title' => 'Admin Panel',
                'allowedRoles' => ['admin'],
                'responsive' => ['hideBelow' => 'md'],
            ],
        ];

        // Order matters: filter by role first, then apply CSS classes
        return $this->getResponsiveItems(
            $this->getAllowableItems($items)
        );
    }
}

Where Generics Live ​

GenericFQCN
AllowableUnusualify\Modularous\Traits\Allowable
ResponsiveVisibilityUnusualify\Modularous\Traits\ResponsiveVisibility
HasFilepondsUnusualify\Modularous\Entities\Traits\HasFileponds
FilepondsTraitUnusualify\Modularous\Repositories\Traits\FilepondsTrait