mimisk / stagebox
Laravel package for stagebox management with owner scoping and slug generation.
Requires
- php: ^8.4
- illuminate/support: ^12.0|^13.0
- mimisk/laravel-toolbox: ^0.0.1
Requires (Dev)
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- phpunit/phpunit: ^11.5.3|^12.0.1
README
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\StageboxEloquent model- internal package migration for the
stageboxestable - 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, default0)color(string, defaultblack)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.