Looking to hire Laravel developers? Try LaraJobs

laravel maintained by forehall

Description
Rooms for Forehall apps: models, a policy and an Inertia room route for Laravel.
Last update
2026/12/03 11:09 (dev-main)
License
Downloads
0
Tags

Comments
comments powered by Disqus

Read-only mirror. This repository is published from packages/laravel in nexence-labs/forehall by its release workflow. Issues and pull requests go to the monorepo.

forehall/laravel

Rooms for Forehall apps on Laravel: the models, a policy and an Inertia room route that a Forehall starter renders with @forehall/space.

Status: alpha, not yet on Packagist. The API will change. For now it is used from inside the Forehall monorepo through a Composer path repository.

What it adds

  • Models. Room (found by slug in URLs) and RoomObject (a name and a Transform: position, rotation in radians, and scale, each three finite numbers, stored as JSON).

  • Migrations for forehall_rooms and forehall_room_objects (with a revision that counts each object's moves), loaded automatically. Publish them with php artisan vendor:publish --tag=forehall-migrations if you want copies.

  • A default room. DefaultRoom::ensure(), or Forehall\Laravel\Database\Seeders\DefaultRoomSeeder, creates the room default with one cube. Running it again changes nothing.

  • A policy. RoomPolicy lets anyone signed in into a room (view) and move its objects (move), and keeps guests out. In v0.1 every signed-in user shares the default room, so anyone who can register can move its objects.

  • A route. GET /rooms/{room} (named forehall.rooms.show, behind web and auth) renders the Inertia page rooms/show with these props:

    {
        "room": { "slug": "default", "name": "Default room" },
        "objects": [
            {
                "id": 1,
                "name": "Cube",
                "transform": {
                    "position": [0, 0, 0],
                    "rotation": [0, 0, 0],
                    "scale": [1, 1, 1]
                },
                "revision": 0
            }
        ]
    }
    

    The props never include users: not the viewer, and not anyone else.

  • Validation. Forehall\Laravel\Rules\ValidTransform checks request input as a transform. Saving a model with a bad transform throws InvalidTransform.

Moving objects

PUT /rooms/{room}/objects/{object} (named forehall.rooms.objects.move, behind the same middleware plus a per-user rate limit) takes {"transform": {...}}. It checks the move ability, refuses a bad transform or one out of bounds with a 422, saves it, adds one to the object's revision, and returns:

{ "object": { "id": 1, "transform": { "...": "..." }, "revision": 3 } }

Then it broadcasts ObjectMoved (as .object.moved) on the room's presence channel to everyone but the mover, with object_id, transform, revision and sender (an opaque participant id). Send Echo's socket id in the X-Socket-ID header to be left out: Inertia 3 doesn't send it for you. The event is broadcast straight away, so no queue worker is needed. If the broadcast fails, the move is still saved and the failure is logged.

Presence

The package registers a presence channel, forehall.rooms.{slug}, for anyone the room policy lets view the room. Members see each other as:

{ "id": "3f9c2a…", "label": "Guest 3F9C" }

The id comes from the user's id and the app key, so it can't be read back. Email is never shared. Set forehall.presence.show_names to true in your published config to add each user's name.

Two things belong in your app:

  • Use Forehall\Laravel\Concerns\BroadcastsAsParticipant on your user model. Laravel puts the user's id in presence channel data, where every member can read it; the trait sends the opaque id instead.
  • Give the broadcasting auth route the room's middleware, for example withBroadcasting(..., ['middleware' => ['web', 'auth', 'verified']]) in bootstrap/app.php.

If the broadcaster can't start (Reverb with no key yet, say), the package logs a warning and skips the channel, so the rest of the app keeps working.

Presence shows who is in a room right now; nothing is stored. Whoever deploys an app built on this decides whether names are shown, and is responsible for telling their users.

It works with your app's own user model: nothing here refers to App\Models\User.

Configuration

Publish config/forehall.php with php artisan vendor:publish --tag=forehall-config to change the route prefix, middleware, route names, page component, the default room's slug and name, the move rate limit (moves.per_minute, 120 by default), the bounds on position and scale (moves.max_position, 1000, and moves.max_scale, 100), and whether presence is on or shows names. Set forehall.routes.enabled to false to register the ShowRoom controller on a route of your own.

Requirements

PHP 8.4, Laravel 13 and inertiajs/inertia-laravel 3. Presence and the move broadcast need a broadcaster that speaks Pusher's protocol, such as Laravel Reverb. Without one the move endpoint still saves.

Development

composer install
composer test      # Pest, through Orchestra Testbench
composer lint      # Pint
composer analyse   # Larastan

Licence

MIT. See LICENSE. The software is provided "as is", without warranty of any kind.