Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/raczkodavid/Zooniverse/llms.txt

Use this file to discover all available pages before exploring further.

Each enclosure in Zooniverse can have one or more caretakers responsible for its daily management. Caretakers are standard user accounts with a restricted view — they only see the enclosures they have been assigned to. Admins manage these assignments directly from the enclosure edit form, and changes take effect immediately upon saving.

The enclosure_user Pivot Table

Users and enclosures share a many-to-many relationship, meaning a single caretaker can be responsible for multiple enclosures and a single enclosure can have multiple caretakers. This relationship is backed by the enclosure_user pivot table, created by the following migration:
Schema::create('enclosure_user', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('user_id');
    $table->unsignedBigInteger('enclosure_id');

    $table->foreign('user_id')->references('id')->on('users')->ondelete('cascade');
    $table->foreign('enclosure_id')->references('id')->on('enclosures')->ondelete('cascade');

    $table->timestamps();
});
Both foreign keys cascade on delete, so removing a user or enclosure automatically cleans up its pivot rows. The relationship is declared on both sides of the models using belongsToMany:
// Enclosure model
public function users(): BelongsToMany
{
    return $this->belongsToMany(User::class)->withTimestamps();
}

// User model
public function enclosures(): BelongsToMany
{
    return $this->belongsToMany(Enclosure::class)->withTimestamps();
}

How the Sync Operation Works

When an admin saves the enclosure edit form, the controller calls sync() on the users() relationship:
$enclosure->users()->sync($request->caretakers);
sync() replaces all existing caretaker assignments for the enclosure with the submitted list. Any user IDs present in the database but absent from the new list are detached, and any new IDs are attached. This is an atomic replacement — there is no need to manually detach old assignments before adding new ones.
If the form is submitted with no caretakers selected, $request->caretakers will be null. Laravel’s sync(null) detaches all caretakers from the enclosure.

What Caretakers See After Assignment

The enclosure index controller checks whether the logged-in user is an admin to determine which enclosures to display:
$enclosures = $isAdmin
    ? Enclosure::orderBy('name')->paginate(5)
    : auth()->user()->enclosures()->orderBy('name')->paginate(5);
Caretakers (non-admin users) only see the enclosures they are assigned to, ordered alphabetically. Unassigned enclosures are invisible to them entirely.
The admin column on the users table is cast to a boolean. Caretakers are any users where admin is false.

Assigning a Caretaker to an Enclosure

Caretaker assignment is only available when editing an existing enclosure — the create form does not include it. Open the edit form for the enclosure you want to configure.
1

Open the enclosure edit form

Navigate to the enclosures list and click the edit button for the target enclosure. The edit form loads the enclosure’s current name, animal limit, and feeding time.
2

Open the caretaker selection modal

Click the Select Caretakers button. A modal dialog appears listing every user account in the system, with checkboxes pre-checked for users who are already assigned.
3

Select the caretakers

Check the boxes next to each user you want to assign to this enclosure. You can select any number of users. Currently assigned caretakers are pre-selected automatically.
4

Save the enclosure

Close the modal and click Edit Enclosure to submit the form. The controller validates the other fields and then calls sync() to apply the updated caretaker list.
To remove a caretaker, re-open the modal, deselect the user, and save the form. The sync() call will detach that user from the enclosure. The user account itself is not affected.

Removing All Caretakers

If you save the form without selecting any caretakers, all existing assignments for that enclosure are cleared. The enclosure remains active — it simply will not appear in any caretaker’s list until at least one user is assigned again.

Build docs developers (and LLMs) love