mimisk/stagebox

Laravel package for stagebox management with owner scoping and slug generation.

Maintainers

Package info

github.com/MimisK13/laravel-stagebox

pkg:composer/mimisk/stagebox

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-04-24 04:55 UTC

This package is auto-updated.

Last update: 2026-07-24 05:33:24 UTC


README

Tests Latest Version on Packagist Total Downloads

mimisk/stagebox is a Laravel package for managing stagebox records with built-in migrations and automatic slug generation.

Installation

Via Composer

composer require mimisk/stagebox

Usage

This package provides:

  • Mimisk\Stagebox\Models\Stagebox Eloquent model
  • internal package migration for the stageboxes table
  • owner-scoped stageboxes via polymorphic relation (stageboxable_type / stageboxable_id)

Run migrations:

php artisan migrate

Define relation on your owner model:

use Illuminate\Database\Eloquent\Relations\MorphMany;
use Mimisk\Stagebox\Models\Stagebox;

class Festival extends Model
{
    public function stageboxes(): MorphMany
    {
        return $this->morphMany(Stagebox::class, 'stageboxable');
    }
}

Create/attach a stagebox through owner relation:

$festival->stageboxes()->create([
    'name' => 'A',
    'channels' => 12,
    'returns' => 4,
    'color' => 'black',
    'notes' => 'Drum Riser',
]);

Attach an existing stagebox to owner:

$stagebox->stageboxable()->associate($festival);
$stagebox->save();

The slug is generated automatically from name when not provided.

Fields:

  • name (string)
  • slug (unique per owner scope)
  • channels (unsigned tiny integer)
  • returns (unsigned tiny integer, default 0)
  • color (string, default black)
  • notes (nullable text)
  • timestamps

Query examples:

use Mimisk\Stagebox\Models\Stagebox;

$all = Stagebox::orderBy('name')->get();
$single = Stagebox::query()
    ->where('stageboxable_type', $festival->getMorphClass())
    ->where('stageboxable_id', $festival->getKey())
    ->where('slug', 'a')
    ->first();

Why detach is not supported

stageboxable_type and stageboxable_id are required columns (morphs, non-null), so a stagebox must always belong to an owner. This means you can re-attach to another owner, but not detach to a null owner.

Prevent orphan stageboxes when owner is deleted

Polymorphic relations do not get database-level cascade delete by default. Delete associated stageboxes before deleting the owner:

public function destroy(Festival $festival): RedirectResponse
{
    $festival->stageboxes()->delete();
    $festival->delete();

    return redirect()
        ->route('festivals.index')
        ->with('status', 'Festival deleted.');
}

Maintenance command

The package includes a maintenance command that deletes orphan stageboxes:

php artisan stagebox:clean-orphans

Testing

composer test

Credits

License

MIT. Please see the license file for more information.