---
title: 'Run one Laravel snippet for multiple tenant IDs'
description: '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.'
canonical_url: 'https://larabench.com/laravel-tinker-workflows/run-laravel-snippet-for-multiple-tenants'
md_url: 'https://larabench.com/laravel-tinker-workflows/run-laravel-snippet-for-multiple-tenants.md'
last_updated: '2026-07-28'
---
# 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, such as a configuration flag, record count, integration state, or small model lookup.

## Terminal Approach

```bash
php artisan tinker
```

```php
use App\Models\Tenant;

foreach ([101, 205, 309] as $tenantId) {
    $tenant = Tenant::query()->findOrFail($tenantId);

    dump($tenant->only(['id', 'name', 'status']));
}
```

## LaraBench Approach

Choose the connection, run one known tenant in Run Code, then open Batch Runs and enter `101,205,309` for the `tenantId` placeholder. Review failed rows before retrying or exporting.

## Snippet Template

```php
use App\Models\Tenant;

$tenant = Tenant::query()->findOrFail({tenantId});

return [
    'id' => $tenant->getKey(),
    'name' => $tenant->name,
    'status' => $tenant->status,
];
```

## Expected Result

Batch Runs shows one row per tenant ID. A successful row has an OK status, exit code 0, duration, and an output preview containing only the returned fields.

## Troubleshooting

- If every row says the model is missing, check the namespace and selected Laravel app.
- If one tenant affects the next, add the tenancy package context cleanup after each check.
- 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, and test one value first.

## Related Sources

- [Laravel Artisan Tinker documentation](https://laravel.com/docs/13.x/artisan#tinker)
- [LaraBench placeholder template docs](https://larabench.com/docs/basic-usage/placeholder-templates)
- [LaraBench Batch Runs docs](https://larabench.com/docs/advanced-usage/batch-runs)

## Related Workflows

- [Check Laravel production with a read-only Tinker snippet](https://larabench.com/laravel-tinker-workflows/safe-laravel-production-check)
- [Inspect Eloquent models and collections](https://larabench.com/laravel-tinker-workflows/inspect-eloquent-models-and-collections)

## Canonical Page

- [HTML page](https://larabench.com/laravel-tinker-workflows/run-laravel-snippet-for-multiple-tenants)
- [Markdown mirror](https://larabench.com/laravel-tinker-workflows/run-laravel-snippet-for-multiple-tenants.md)

## Glossary

- [Laravel workflow glossary](https://larabench.com/docs/reference/glossary)

## Sitemap

See the full [sitemap](https://larabench.com/sitemap.md) for all public pages.
