Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

juanborras's avatar

Is Filament the right solution?

Hey there!

I'm developing an app on filament to control the wc usage at my school. From the admin panel, staff, toilets, students and so on are configured.

To make the UI easy for the staff I will use a Livewire component with a filament table for the Toilets, where the location and the status are shown (free, busy). When the Toilet is free, by clicking on the row, a modal (?) opens where the staff selects the group and the student and by confirming the modal closes and the status of the Toilet updates to "busy". By clicking on a busy Toilet, the status changes back to free, internally, a record is saved to a log where the teacher, timestamp and student are recorded.

I think the best solution is to have a Livewire component with the Table where the Toilets are shown and a Fillament Form to fill the student info and so on.

Am I in the right path? or I'm missing something that will f... me up later on?

0 likes
8 replies
LaryAI's avatar
Level 58

Yes, using Filament along with Livewire for your application seems like a suitable approach. Filament provides a robust admin panel with built-in tools for managing models and their relationships, which is ideal for your use case where you need to manage toilets, students, and staff. Livewire will allow you to create a dynamic and responsive user interface, which is crucial for the real-time updates and interactions your application requires.

Here's a basic outline of how you might structure your solution:

  1. Filament Table for Toilets: You can use Filament to create a table that lists all the toilets with their current status. This table will be reactive and can update in real-time using Livewire.

  2. Modal for Updating Toilet Status: When a toilet row is clicked, you can use Livewire to trigger a modal popup. This modal will contain a form where the staff can select the group and the student. Submitting this form will update the status of the toilet and close the modal.

  3. Changing Toilet Status: For changing the status from busy to free, you can handle this directly in the Livewire component, possibly with a simple button in the table that toggles the status.

  4. Logging the Changes: Each change in toilet status should trigger a method in your Livewire component that logs the necessary information (teacher, timestamp, student) to a database.

Here is a simplified example of what the Livewire component might look like:

use Livewire\Component;
use App\Models\Toilet;
use App\Models\Log;

class ToiletStatus extends Component
{
    public $toilets;
    public $selectedToilet;

    public function mount()
    {
        $this->toilets = Toilet::all();
    }

    public function render()
    {
        return view('livewire.toilet-status');
    }

    public function openModal($toiletId)
    {
        $this->selectedToilet = Toilet::find($toiletId);
        $this->dispatchBrowserEvent('modal-open');
    }

    public function updateToiletStatus($studentId, $groupId)
    {
        $this->selectedToilet->status = 'busy';
        $this->selectedToilet->save();

        Log::create([
            'teacher_id' => auth()->id(),
            'student_id' => $studentId,
            'timestamp' => now(),
        ]);

        $this->dispatchBrowserEvent('modal-close');
    }

    public function freeToilet($toiletId)
    {
        $toilet = Toilet::find($toiletId);
        $toilet->status = 'free';
        $toilet->save();

        // Log this action as well
    }
}

And a simple modal in your Livewire view might look like this:

<div x-data="{ open: false }" x-on:modal-open.window="open = true" x-on:modal-close.window="open = false">
    <template x-if="open">
        <div class="modal">
            <!-- Form for selecting group and student -->
            <button @click="updateToiletStatus(selectedStudent, selectedGroup)">Confirm</button>
        </div>
    </template>
</div>

This example assumes you have some familiarity with Alpine.js for handling the modal, but you can adapt it to use pure Livewire or another JavaScript framework if preferred.

Overall, your approach is sound, but be sure to handle edge cases, such as simultaneous updates to the same toilet status, which might require additional state management or locking mechanisms to prevent race conditions.

Tray2's avatar

I'm just gonna say WTF!

Monitoring who uses the bathroom like is fucked up.

juanborras's avatar

@Tray2 Probably. We had to close them due wrong use and vandalism. It cost a lot of money to fix them. So, that's the solution so far.

Tray2's avatar

@juanborras I suggest hiring more ppl to monitor the bathrooms instead, cause it might not even be legal to store that kind of information.

1 like
martinbean's avatar

It's a internal app and there's consent about the data

@juanborras That’s still probably going to be illegal in most countries and jurisdictions.

juanborras's avatar

Thank you all for your data protection concerns. It is all legally covered.

Please or to participate in this conversation.