PHP and Laravel
Keep Eloquent and your own migrations. Mantis gives the branch database as plain Postgres, the files as a disk, and branches and rewind.
A Laravel app does not need mantis/schema.ts. It keeps its own migrations and Eloquent and talks
to the branch database as plain Postgres. Branches, rewind and files work the same as for any
other app.
Set it up
Add shipmantis/mantis with Composer. It comes from the private thealexsan/mantis-php
repository, so Composer needs a GitHub token that can read it:
composer config --global github-oauth.github.com "$(gh auth token)"
composer config repositories.mantis vcs https://github.com/thealexsan/mantis-php
composer require shipmantis/mantis:^0.1Then set the keys:
MANTIS_URL=https://data.shipmantis.com
MANTIS_SECRET_KEY=sk_...
MANTIS_BRANCH=main # optionalThe default database connection becomes the branch database. php artisan migrate migrates it,
and Eloquent uses it. Nothing asks Mantis until the first query, and the connection is cached for
an hour.
| Setting | What it does |
|---|---|
MANTIS_BRANCH | The branch to run on. Make one with npx shipmantis branch create try-it. |
MANTIS_DATABASE_HOST | host:port when the app sees Postgres under another name, like a Docker network. |
MANTIS_DATABASE=false | Leave the database to your own settings. |
MANTIS_DATABASE_DEFAULT=false | Add a mantis connection without making it the default. |
php artisan mantis:connect --dotenv prints the DB_* lines instead, for an app that would
rather set them itself. They hold the password, so keep them out of git.
Files
'mantis' => ['driver' => 'mantis'],Storage::disk('mantis')->put('lessons/intro.mp4', $video);
Storage::disk('mantis')->temporaryUrl('lessons/intro.mp4', now()->addMinutes(5));Uploads go straight to the bucket in parts; the bucket keys never leave Mantis. A link lasts a few minutes. Who reads a file is set on its folder, on the Files page.
Queries, branches, rewind
use Shipmantis\Mantis\Laravel\Facades\Mantis;
Mantis::table('todos')->insert(['title' => 'Ship it']);
Mantis::branches()->create('try-it');
Mantis::previewRewind(now()->subMinutes(30));Rewind and migrations
Rewind covers the tables your migrations made and skips Laravel's migrations table. It goes no
further back than the last migration or rollback: name a time before one, and it refuses.