calebporzio/sushi
Sushi adds an “array driver” to Eloquent: define a model with the Sushi trait and a $rows array, and query it like a real table (where, first, eager loading, relationships). Great for fixture data like states, roles, and settings—no DB setup needed.
Start by installing the package and ensuring the pdo-sqlite extension is enabled in your PHP environment:
composer require calebporzio/sushi
Then, create a model and use the Sushi trait along with a $rows array:
use Illuminate\Database\Eloquent\Model;
use Sushi\Sushi;
class Country extends Model
{
use Sushi;
protected $rows = [
['id' => 1, 'name' => 'United States', 'code' => 'US'],
['id' => 2, 'name' => 'Canada', 'code' => 'CA'],
];
}
Now you can query it like any Eloquent model:
$country = Country::where('code', 'US')->first();
Ideal for static reference data (e.g., countries, states, roles, settings) where database persistence isn’t needed.
$rows for immutable, small-to-medium datasets (e.g., tax rates, timezones, product categories).getRows(): Implement getRows() to source data at runtime (e.g., from a config file, API, or CSV). Combine with sushiShouldCache() and sushiCacheReferencePath() to cache results and watch external files for cache invalidation.belongsTo, hasMany) with regular Eloquent models—just avoid whereHas()/whereDoesntHave() due to cross-database limitations.exists:App\Models\YourModel,column in validation rules, as the sushi. connection prefix is no longer needed (v2.3.1+).$schema = ['column' => 'type'] to override auto-detected column types (e.g., force integer for '001' → 1).afterMigrate(Blueprint $table) to add indexes or constraints (e.g., $table->index('name')).whereHas doesn’t work across Sushi and database-backed models due to separate SQLite connections—prefetch related data or use raw queries if needed.public $incrementing = false;
protected $keyType = 'string';
$schema—essential for models that may return no rows from getRows().$rows is cached automatically and busts when the model file changes.getRows() datasets are not cached unless sushiShouldCache() returns true.sushiCacheReferencePath() to tie cache invalidation to an external file (e.g., CSV).public $sushiInsertChunkSize = 50; to avoid SQLite’s too many SQL variables error.123 → integer, '123' → string), but explicit $schema ensures correctness.$timestamps = true, created_at/updated_at columns are auto-added—even when using $rows.storage/sushi/ (customize via config('sushi.cache-prefix')) or enable sushi.log debugging (if added by config).How can I help you explore Laravel packages today?