24 KiB
iriks-it/laravel-manager
A modular backend for Laravel sites. Install it, switch on the parts the site needs, done.
composer require iriks-it/laravel-manager
php artisan vendor:publish --tag=manager-config
php artisan migrate
Put IriksIT\Manager\Concerns\HasManagerAccess on the User model. The manager lives at /manager
(MANAGER_PATH) behind the web and auth middleware (config/manager.php).
Set up with an AI agent
php artisan manager:install --modules=users,media,posts --user-model="App\Models\User"
php artisan manager:doctor --json # non-zero exit when something is wrong; each problem has a `fix`
resources/ai/INTEGRATION.md is a step-by-step guide for an agent; resources/boost/guidelines/core.blade.php
is picked up by Laravel Boost.
Screens and themes
The package brings its own screens (a small Vue app on the JSON routes, already built: your app needs no Node). They also
give an app without a login a login and a profile. MANAGER_UI=none turns them off, for an app that builds its own screens
on the JSON routes. A browser that opens a manager address gets the page; anything that asks for JSON gets the data.
- Looks. Built in are
darkandlight.MANAGER_THEMEis what everyone sees until they choose; withMANAGER_USER_THEMES=true(default) each account picks its own in its profile. - The house style of the site.
php artisan manager:make-theme acme --brand=#e4002b --name="Acme" --logo=/img/logo.svg --font="Inter, sans-serif"writesresources/manager-themes/acme.json; setMANAGER_THEME=acme. A theme is colours, a radius, fonts, a name and a logo, and every value is checked, so a theme file can never put CSS or markup in the page. Themes can also be listed inmanager.themes. - Not built yet: a theme editor in the manager (themes are files for now), and screens for modules your own site adds (they show a notice).
- Working on the screens: the sources are in
ui/;npm ci && npm run buildthere writesresources/dist, which is committed (PR CI fails when it is out of date).
Modules
| Key | What | Default |
|---|---|---|
users |
Accounts, groups and permissions | on |
media |
Media library | on |
pages |
Page texts | on |
posts |
Posts | on |
reviews |
Reviews | off |
audit |
Audit log and address bans | off |
statistics |
Visitor statistics | off |
resources |
Lists defined in config (manager.resources) |
on (nothing without definitions) |
revisions |
History of posts and pages, with restore | on |
Switch a part in config/manager.php (modules) or with MANAGER_PAGES, MANAGER_POSTS,
MANAGER_REVIEWS, MANAGER_AUDIT, MANAGER_STATISTICS, MANAGER_REVISIONS. A module that is off has no routes, no tables, no menu item and no permissions:
its migrations are not loaded at all. A module that needs another one (requires()) fails at boot when
that one is off.
Language
The texts the server makes (menu, permission and section labels, theme names, audit summaries and the messages of the JSON routes) go through Laravel's __() with the English text as the key. The package ships resources/lang/nl.json; the screens follow app()->getLocale(). A site translates more, or words things differently, with its own lang/<locale>.json: that file wins over the package. Audit lines are written in the language of the request that made them.
The menu and the simple view
A module's menu item is ['label' =>, 'route' =>, 'permission' =>] and may add section (a heading), icon (home, file, image, users, group, chart, shield, star, tag, link, cog), order (lower first, default 100), simple and new_tab. A site changes the menu without code in config/manager.php: menu.items by route name without the prefix ('posts.index' => ['order' => 10, 'section' => 'Content', 'hidden' => false]) and menu.links for items of its own (['label' => 'Leads', 'url' => '/manager/leads', 'permission' => null]).
simple_view (MANAGER_SIMPLE_VIEW=true) adds a simple face next to the full one, for an owner who only needs a few screens. Two permissions appear in the group form: manager.full (everything; super admins have it) and manager.switch (starts simple and may switch; the choice is remembered per account and the menu has a button for it). Every other account always gets the simple face: only the items marked simple. It limits the menu, not the access: the routes still check their own permissions. Turning it on makes accounts without manager.full or manager.switch see only the simple items, so give the groups what they need first.
Your own lists and screens
Lists without code. manager.resources turns a definition into a menu item, a list, a form, validation and the permissions <key>.view and <key>.manage, for things like a menu, socials, services, testimonials or leads:
'resources' => [
'services' => [
'label' => 'Services', 'singular' => 'Service',
'model' => App\Models\Service::class, // the records live in a model of the site; leave it out to use the package's own table
'columns' => ['name', 'price'], 'order' => ['position', 'asc'],
'fields' => ['name' => ['type' => 'text', 'required' => true], 'price' => ['type' => 'number'], 'photo' => ['type' => 'media']],
],
],
The field keys are the attributes of the model (the definition is the whitelist: nothing else is written); without a model the values are kept as JSON in manager_records. Field types are the ones of the pages. Names that belong to a module (posts, pages, media, ...) are refused.
Screens of your own. List a JavaScript module in manager.extensions (a path of your site, or https). The manager loads it before it shows anything and puts window.IriksManager in reach: Vue, boot, api, t, flash, navigate, register and the components Link, FormFields, Icon and MediaPicker. register('^/leads$', Component, { data: true }) shows Component at /manager/leads, with the JSON of that same address (or of source) as props; an address of yours needs a route for the data, and a menu item through manager.menu.links. Build your bundle with vue left external (build.rollupOptions.external: ['vue']): the manager points import 'vue' at its own Vue, so your components share its reactivity. A browser that opens a manager address without a route of the package gets the screens (which show yours, or "no screen yet"); a request for data gets a plain 404.
A site with data and names of its own
The package never maps its queries onto other tables: every screen assumes its own columns. What it does give you is room to coexist and a way to move data in.
route_name(defaultmanager): the prefix of the route names. A site that already hasmanager.*routes sets, for example,'route_name' => 'cms'; the menu and the screens follow. UseIriksIT\Manager\Support\Names::route('posts.index')in code of your own.table_prefix(defaultmanager_) andtables(['media' => 'site_files']): the names of the tables. Set them before the firstmigrate; the package does not rename a table that exists.php artisan manager:import posts --table=articles --map=title=headline --map=body=content [--dry-run] [--connection=...] [--limit=...]copies the rows of a table of the site intoposts,pagesorreviews. The source is only read, and running it again updates the rows it made (found by slug, or by author and text for reviews).--mapispackage_column=source_column. Put the settings inmanager.import.<target>(table,connection,map) to run it without options. Tags may be JSON or a comma separated list; a row without the required text is skipped and reported.
Your own module
Implement IriksIT\Manager\Contracts\Module (or extend Modules\BaseModule), keep routes.php and a
migrations/ folder next to the class, and add the class to available in the config.
Users module
Accounts and groups. HasManagerAccess on the host User model gives it managerGroups(),
managerPermissions(), hasManagerPermission(), managerOutranks() and managerMayGive().
Keep is_super_admin out of $fillable: nobody becomes a super admin through a form.
php artisan manager:create-user # the only way to make a super admin
- A group is a name plus permissions; a permission that needs another one (
posts.publishneedsposts.write) brings it along. Permissions of a module that is off are ignored. - Whoever manages accounts only touches accounts that need nothing more than their own rights, and only hands out groups that give nothing they lack themselves.
groups.manageis a gate for super admins only, not a permission of a group.- The package defines one gate per permission and no
Gate::before: it never answers for the abilities of your own app. - A site with roles of its own (decided in 0.5.0: groups stay the default, the site's roles are added next to them).
manager.permissions.modeisgroups(default),host(the groups are ignored) ormerge(both). The site says what a role may do withroles(['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']], read from the attributerole_attribute: a string, a list or a relation with aname) or with aresolverclass that implementsIriksIT\Manager\Contracts\PermissionResolver. Values that are no permission of an active module are ignored and what a permission needs is added. A super admin may always do everything. The group screens still work inhostmode but give nothing. - The migration adds
is_super_adminto your users table (the table ofmanager.user_model). It promotes nobody.
Checks on the login
The login of the screens can ask for more. Write a class that extends IriksIT\Manager\Support\Login\BaseLoginCheck (the contract is IriksIT\Manager\Contracts\LoginCheck) and list it in manager.login.checks:
fields(): extra inputs on the form (['name' => 'code', 'type' => 'text', 'label' => 'Code', 'autocomplete' => 'one-time-code']);before($request): runs before the password is looked at: a captcha;after($request, $user): runs when the email and password are right and before anyone is logged in: a second factor. Refuse by throwing aValidationException; the attempt then counts as a failed login, so the audit log and the bans see it.
Cloudflare Turnstile is built in: set MANAGER_TURNSTILE_SITE_KEY and MANAGER_TURNSTILE_SECRET and the widget appears and is checked (a token that cannot be checked refuses the login). The widget loads a script from challenges.cloudflare.com; a strict Content-Security-Policy has to allow it. There is no two-factor login in the package itself: after() is the place for it, the code to make and keep the secrets is the site's. These checks belong to the login of the screens (MANAGER_UI=package); an app with its own login keeps its own.
Media module
Files live on a Laravel filesystem disk (manager.media.disk); each row remembers its own disk.
- Manager (behind
manager.middleware):GET /manager/media,/manager/media/items,POST,PUT /{id},DELETE /{id}. Limits (total room, file size, extensions) are inmanager.media.*. - Visitors:
GET /media-files/{id}/{filename}/view, outside the manager, no session. ETag, byte ranges,nosniff, and only images, video and PDF are shown inline. Rate limitermedia-files. - Where a file is used: other modules or your app register a source with
app(IriksIT\Manager\Support\MediaUsage::class)->register(fn () => $texts). Posts and Pages do. - No SVG: it can carry scripts.
Pages module
Pages are texts with keys, so the public site reads them and the owner edits them without code. Define a page in config/manager.php:
'pages' => ['definitions' => ['home' => ['title' => 'Home', 'fields' => [
'hero_title' => ['label' => 'Title on the photo', 'type' => 'text', 'default' => 'Welcome', 'max' => 120],
'intro' => ['label' => 'Story', 'type' => 'markdown'],
'photo' => ['label' => 'Photo', 'type' => 'media'],
]]]],
and read it with IriksIT\Manager\Models\Page::contentFor('home'): the stored values over the defaults, so a page that was never saved still has all its keys. Field types: text, textarea, markdown, lines, media, url, number, date, toggle and select (with options); required, default, max, help and rules work on all. The screens make the form, and the server validates and cleans every value by its type (a media or url value must be an address of the site or http(s)). A page without a definition is a free page with one Markdown text, a description for search engines and a publish switch; it can be made and removed in the screens. Permission: pages.edit. The definitions are shared code (IriksIT\Manager\Support\Fields), so other records can use them.
Posts module
Posts written in Markdown, with drafts, scheduling, categories and tags.
- Routes under
/manager:posts(list,create,{id}/edit,{id}/preview, update,{id}/online, delete) andlabels(categories and tags: make, rename, merge, remove). Rights:posts.view,write,publish,delete,labels. - Who may not publish only saves drafts, and cannot change or delete a post that is live or scheduled.
- A post is a draft (
published_atnull), scheduled (in the future) or published. For your public pages:IriksIT\Manager\Models\Post::published(),toCard()andIriksIT\Manager\Support\Markdown::toHtml()(raw HTML is escaped, external links open in a new window). The package has no public post routes: the host decides what a visitor sees. - Categories offered in the form:
manager.posts.categories, the ones in use, the ones made by hand and whatever your site adds withapp(IriksIT\Manager\Modules\Posts\PostLabels::class)->suggestCategories(fn () => $titles). - Covers and bodies count as use of a media file.
The editor
Texts in Markdown (posts, free pages and markdown fields) have a toolbar (bold, italic, heading, list, quote, link), a Photo button that puts a picture from the media library into the text, and a Preview that is rendered by the server the way the site renders it (raw HTML is escaped; POST /manager/markdown, not written in the audit log). In the media library a click on a picture sets its focus point (focus_x, focus_y, 0 to 1): the part that must stay in view when the site crops it, shown in a square preview. There is no cropping or rotating in the manager: the file is kept as it was uploaded, and the site crops with the focus point.
History module
Every save of a post or a page keeps its state (manager_revisions, the newest 50 per record, manager.revisions.keep), with who saved it and which fields changed; saving the same state again keeps nothing. The post and page screens show the history, and revisions.restore puts an earlier state back, which is a save like any other (so what was there is in the history too). Whether a post is on the site (published_at) and whether a page is published is not part of the history: going back in time never publishes or hides anything. A live post can only be put back by someone who may publish. Permissions: revisions.view (and the permission to see that kind of text) and revisions.restore (and the permission to write it). A site adds its own models with manager.revisions.types, e.g. 'services' => ['model' => App\\Models\\Service::class, 'view' => 'services.view', 'restore' => 'services.manage']. MANAGER_REVISIONS=false turns the module off.
Audit module
Off by default: it stores IP addresses and browser lines, so a site switches it on knowingly and says so in its
privacy policy (MANAGER_AUDIT=true).
- The log: logins, logouts and failed logins (from Laravel's own
Login,LogoutandFailedevents, so it works with any login the host has), every change in the manager, every page that is opened (not twice within five minutes) and every refusal. Only the account, the address and the browser line are kept, and for an action the fields its module listed, never what was typed into a form. The log is read withaudit.view. - Names: a module says what its routes are called in the log with
actions()andviews(); a test fails on a manager route without a name. - Bans (
audit.manage): ban an address by hand, for a time or until lifted, or a whole group of addresses (notes put addresses in a group). After too many failed logins an address is banned by itself (the rules are set in the manager). A banned address gets a 403 (429 for an automatic ban) on every manager route. Put themanager.not-bannedmiddleware on the login routes of your app too. A site that is locked out lifts the ban withphp artisan manager:unban {ip}. - Behind a proxy: set up trusted proxies (or
MANAGER_NEVER_BAN) before switching the module on. Without them every visitor shares one address, and one bad actor can lock the whole manager out. Failed logins on any guard count towards the automatic ban. - Whole-site bans: with
MANAGER_AUDIT_WHOLE_SITE_BANS=truea ban can also keep an address off the whole app. That adds a global middleware that is answered from the cache. - Config (
manager.audit):never_ban(MANAGER_NEVER_BAN, comma-separated: your own addresses), andmax_keep_days(MANAGER_AUDIT_MAX_KEEP_DAYS, 90): the longest the log may be kept, which your privacy policy has to agree with.manager:audit-pruneruns daily and deletes old lines and ended bans; notes stay until removed.
Statistics module
Off by default (MANAGER_STATISTICS=true). The site's own visitor statistics, with no cookie and no stored IP address:
a visitor is a code made of the address, the browser and a random key that is deleted after a day (manager:forget-visitor-keys,
scheduled daily), so a code cannot be traced back afterwards. A browser that sends DNT or Sec-GPC is not counted.
- The script: put
<x-manager::pulse />once in the layout of the public site (:spa="true"for a site with a client-side router). It loads/pulse/pulse.js(about 2 kB, plain JavaScript, no cookies or storage), reports the page and the time it was in view, and does nothing for a browser with Do Not Track or Global Privacy Control. With the module off the component prints nothing. Behind a Content-Security-Policy allow that one script address. - Reporting (what the script does, for a site that wants to do it itself): the pages of your site
POSTto/pulse/view({path, referrer, via, campaign}, answers{token}) and, when the visitor leaves,/pulse/leave({token, seconds}). No session, rate limited (manager.statistics.per_minute). - Which pages count: only addresses you name, so nobody can fill the statistics with made-up ones:
manager.statistics.pages, the posts undermanager.statistics.posts_path(published ones only), and anything else throughapp(IriksIT\Manager\Modules\Statistics\CountedPages::class)->register(fn (string $path) => ...). - Programs: the pages served to search engines, crawlers and previews are counted per day, program and page (no address, no browser
line), by a middleware the module adds to the
webgroup (manager.statistics.count_bots). - The report (
statistics.view): visitors, visits, page views, time, bounce rate, a comparison with another period, pages, posts, sources and channels, devices, heatmap, programs;GET /manager/statistics?range=30dand a CSV per sheet (/manager/statistics/export?sheet=days|pages|sources|bots). - Country only when
manager.statistics.country_headernames a header (Cloudflare:CF-IPCountry).
State of this version
Done: module registry and switches, permissions per module, users (accounts, groups, command, roles of the host), media (library and
public file route, focus point), posts (with categories and tags), pages with fields, lists defined in config, the history with restore,
the audit log with bans, the statistics (with the counting script), the built-in screens for all of these (with a login, checks on the
login, a profile and the simple view), an editor, themes, translations, a site's own bundle of screens, the import of existing data, and
the install and doctor commands for AI agents. composer test runs the tests.
Reviews are still a read-only list. The answers of every action are JSON in the shape the screens use, so an app can build its own screens
with MANAGER_UI=none. Not in the package: two-factor login (the login checks are the place for it), cropping or rotating pictures, a theme editor.
Development cycle
develop ── feature/*, fix/* ──► release/vX.Y.Z ──► production ──► tag vX.Y.Z ──► Packagist
▲ (pull request, (collects the (pull request, │
│ merges by itself) features) merged by hand) │
└──────────────────────── sync: production into develop ◄─────────────────────────┘
- Start a release: Actions → Start release → version (
0.2.0). That makesrelease/v0.2.0fromdevelop. - Features: branch
feature/…orfix/…fromdevelop, open a pull request to the release branch. It merges by itself when PR CI is green. Every pull request adds its row toTOKENS.md. - Ready: add a section
## v0.2.0 - datetoCHANGELOG.mdand open a pull request from the release branch toproduction. A person merges it. - Release (automatic, on the merge): tests and audit once more, the tag
v0.2.0and a Gitea release with the changelog text, Packagist is told, andproductionis merged intodevelop.
Nobody opens a pull request to develop, and production and the release branches take no direct pushes.
| When | What runs |
|---|---|
| Pull request to a release branch or to production | flow (right branches, version above the latest tag, changelog section, tests of these scripts), ledger (TOKENS.md), test (Pint, Pest with the newest and the oldest dependencies, composer validate), security (composer audit, Trivy on the dependencies, secrets and settings). The check PR CI / pr-ci is green when all are. |
| Push to production | verify (Pest, audit), tag and release, Packagist, sync develop |
| Every Monday | composer audit and Trivy on production |
| Every Monday | Dependency updates: a direct dependency with a release outside its constraint (a new major) gets its constraint widened in a pull request renovate/deps-DATE to the open release branch; the npm packages of the screens (ui/) move to their newest release that has been public for 48 hours, with a rebuilt resources/dist, in renovate/ui-deps-DATE. PR CI tests them and they merge when green. Nothing happens while no release is open. The central Trivy (every night 03:00 UTC) and Renovate (04:00 UTC) of the homelab also pass over this repo, but read a composer.lock and a package has none, so they find little here. |
| Every night | Prune branches: removes feature/* and fix/* branches whose last commit is over 30 days old and that have no open pull request (a branch of a pull request can be restored from it in Gitea) |
Secrets of the repository for this: DEPLOY_TOKEN (the organisation has it), and PACKAGIST_USERNAME and
PACKAGIST_TOKEN (until they are set that step only says so). When Packagist does not know the package yet, that step
submits it through the create-package API; after that it only tells Packagist about each new tag.
What Composer installs
.gitattributes leaves what only belongs to the repository out of the package (export-ignore): .gitea/,
dev/, scripts/, tests/, TOKENS.md, AGENTS.md, phpunit.xml and the dotfiles. They stay in the repository.
Packagist builds the archive from git archive, so what a site installs is src/, config/, routes/,
resources/, composer.json, README.md and CHANGELOG.md. Check it with git archive HEAD | tar -t.