Run one Laravel snippet for multiple tenant IDs
Run a read-only check for one tenant ID, then use a {tenantId} template to run the same check for a list in Premium Batch Runs.
Direct answer
Put the changing ID in a {tenantId} placeholder. Run the read-only check once in free Run Code. For a list such as 101,205,309, Premium Batch Runs runs the template once per value and records status, duration, exit code, and output for each row.
When to use this
Use this for a diagnostic where the code stays the same and only the tenant changes: configuration flags, record counts, integration state, or a small model lookup. The example assumes your app has an App\Models\Tenant model. Replace the model and fields with the tenant API your application actually uses.
Terminal approach
Start Tinker and run the check over a short, explicit list. Confirm the query and returned fields before saving a template:
php artisan tinkeruse App\Models\Tenant;
foreach ([101, 205, 309] as $tenantId) {
$tenant = Tenant::query()->findOrFail($tenantId);
dump([
'id' => $tenant->getKey(),
'name' => $tenant->name,
'status' => $tenant->status,
]);
}If your tenancy package needs an explicit initialize and end step, keep those calls inside the loop so one tenant context does not leak into the next.
LaraBench approach
- Choose the connection and confirm its environment.
- Open Run Code and paste the template below.
- Run it once with a known tenant ID and check the selected fields.
- Open Batch Runs, use the same template, and enter
101,205,309fortenantId. - Review failed rows before retrying or exporting the results.
Snippet template
use App\Models\Tenant;
$tenant = Tenant::query()->findOrFail({tenantId});
return [
'id' => $tenant->getKey(),
'name' => $tenant->name,
'status' => $tenant->status,
];A single placeholder prompt in Run Code is free. Running the template across multiple values, retrying incomplete rows, and exporting CSV, Markdown, or JSON are part of Premium Batch Runs.
Expected result
Batch Runs shows one row per tenant ID. A successful row has an OK status, exit code 0, its duration, and an output preview containing only the fields returned by the snippet. A missing tenant fails only that row.
Troubleshooting
- If every row says the model is missing, check the namespace and the selected Laravel app.
- If one tenant affects the next, add your tenancy package's context cleanup after the check.
- If the placeholder dialog does not open, confirm the template contains
{tenantId}exactly. - If a row times out, reduce the query and run that tenant separately in Run Code.
Safety notes
Keep batch diagnostics read-only. A write inside the template runs once for every value in the list. Use explicit tenant IDs, return only the fields you need, test one value first, and use LaraBench dry run where the database driver and operation support it.
Related workflows
For a single remote target, start with the read-only production check. For repeated queue work, see the saved failed-job command.
Run these checks in LaraBench.
The free app includes Run Code, Artisan commands, Docker and SSH connections, saved items, History, logs, and benchmarks.