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.

Zooniverse uses Laravel’s soft-delete mechanism for animals, which means that deleting an animal does not permanently erase its record from the database. Instead, the record is stamped with a deleted_at timestamp and hidden from normal queries. Archived animals can be reviewed at any time and restored to a compatible enclosure, making this a safe and reversible operation.

What Soft-Delete Means

The Animal model uses the SoftDeletes trait:
use Illuminate\Database\Eloquent\SoftDeletes;

class Animal extends Model
{
    use HasFactory, SoftDeletes;
    // ...
}
The animals table has a deleted_at column added by the migration:
Schema::table('animals', function (Blueprint $table) {
    $table->softDeletes();
});
When an animal is archived:
  • Its deleted_at column is set to the current timestamp.
  • Its enclosure_id is set to null, removing it from its enclosure.
  • All standard Eloquent queries (e.g., Animal::all()) automatically exclude soft-deleted records.
  • The row remains in the animals table and can be retrieved with Animal::onlyTrashed().
Archiving an animal frees its slot in the enclosure immediately. The enclosure’s animal count decreases, which may allow new animals to be added even if the enclosure was previously full.

How to Archive an Animal

An admin deletes an animal from the enclosure detail view. The controller sets enclosure_id to null before soft-deleting, so the animal is cleanly disassociated from its enclosure:
public function destroy(string $id)
{
    $animal = Animal::findOrFail($id);

    $animal->enclosure_id = null;
    $animal->save();

    // soft delete — sets deleted_at, does not remove the row
    $animal->delete();

    return redirect()->back();
}
1

Navigate to the enclosure

Open the enclosure that contains the animal you want to archive.
2

Click the delete button

Locate the animal in the list and click its delete button. No confirmation dialog is shown — the action is immediate.
3

Confirm the animal is removed

The page reloads and the animal no longer appears in the enclosure. It is now visible on the archived animals page.
There is no confirmation prompt before archiving. The action is instant, though it is fully reversible via the archived animals page.

Viewing Archived Animals

Navigate to /animals/archived to see a table of all soft-deleted animals. The controller retrieves them using onlyTrashed() and sorts by deleted_at descending so the most recently archived animals appear first:
public function archived()
{
    $archivedAnimals = Animal::onlyTrashed()->get()->sortByDesc('deleted_at');
    $enclosures = Enclosure::all();
    return view('zoo.show_archived_animals', compact('archivedAnimals', 'enclosures'));
}
The archived animals table shows:
ColumnDescription
Animal NameThe animal’s name
SpeciesThe animal’s species
Archived AtThe deleted_at timestamp
ActionsA Restore button for each animal

How to Restore an Animal

Each row in the archived animals table has a Restore button that opens a modal dialog. The modal shows the animal’s name and species, and presents a dropdown of valid enclosures — only enclosures that are both type-compatible and not full are listed.
public function restore(Request $request, string $id)
{
    $animal = Animal::onlyTrashed()->findOrFail($id);

    $enclosure = Enclosure::find($request->enclosure_id);

    if (!$animal->isCompatibleWithEnclosure($enclosure))
        return redirect()->back()->withErrors(['enclosure_id' => 'The selected enclosure is not compatible with the animal type.']);

    if ($enclosure->isFull())
        return redirect()->back()->withErrors(['enclosure_id' => 'The selected enclosure is full.']);

    $animal->enclosure_id = $request->enclosure_id;
    $animal->restore();

    return redirect()->back();
}
1

Go to the archived animals page

Navigate to /animals/archived. All soft-deleted animals are listed here in order of most recently archived.
2

Click Restore

Click the Restore button on the row of the animal you want to restore. A modal opens showing the animal’s details and a dropdown of valid enclosures.
3

Select a target enclosure

Choose an enclosure from the dropdown. Only enclosures that pass both compatibility and capacity checks are shown.
4

Confirm the restore

Click Restore inside the modal. The system validates compatibility and capacity server-side, then calls restore() to clear deleted_at and assigns the selected enclosure_id.

Validation on Restore

Two checks are enforced before an animal can be restored: Type compatibility — The animal’s is_predator flag must match the enclosure’s existing animal type. An enclosure with no animals accepts either type.
public function isCompatibleWithEnclosure(Enclosure $enclosure): bool
{
    return $this->is_predator == $enclosure->isPredatorEnclosure()
        || $enclosure->isPredatorEnclosure() === null;
}
Capacity — The enclosure must not already be at or above its animal limit.
public function isFull(): bool
{
    return $this->animals->count() >= $this->limit;
}
The dropdown in the restore modal only shows enclosures that pass both checks at the time the page loads. If the enclosure state changes between page load and form submission (e.g., another animal fills the last slot), the server-side validation will catch it and return an error.

Build docs developers (and LLMs) love