[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8578":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":16,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":16,"starSnapshotCount":16,"syncStatus":27,"lastSyncTime":28,"discoverSource":29},8578,"sushi","calebporzio\u002Fsushi","calebporzio","Eloquent's missing \"array\" driver.","https:\u002F\u002Fusesushi.dev",null,"PHP",3006,187,39,22,0,1,10,28.82,"MIT License",false,"main",[],"2026-06-12 02:01:55","# Sushi 🍣\nEloquent's missing \"array\" driver.\n\nSometimes you want to use Eloquent, but without dealing with a database.\n\n## This Package Is Sponsorware 💰💰💰\nOriginally, this package was only available to my sponsors on GitHub Sponsors until I reached 75 sponsors.\n\nNow that we've reached the goal, the package is fully open source.\n\nEnjoy, and thanks for the support! ❤️\n\nLearn more about **Sponsorware** at [github.com\u002Fsponsorware\u002Fdocs](https:\u002F\u002Fgithub.com\u002Fsponsorware\u002Fdocs) 💰.\n\n\n## Requirements\n\nThe [`pdo-sqlite` PHP extension](https:\u002F\u002Fwww.php.net\u002Fmanual\u002Fen\u002Fref.pdo-sqlite.php) must be installed on your system to use this package.\n\n## Install\n```\ncomposer require calebporzio\u002Fsushi\n```\n\n## Use\n\nUsing this package consists of two steps:\n1. Add the `Sushi` trait to a model.\n2. Add a `$rows` property to the model.\n\nThat's it.\n\n```php\nclass State extends Model\n{\n    use \\Sushi\\Sushi;\n\n    protected $rows = [\n        [\n            'abbr' => 'NY',\n            'name' => 'New York',\n        ],\n        [\n            'abbr' => 'CA',\n            'name' => 'California',\n        ],\n    ];\n}\n```\n\nNow, you can use this model anywhere you like, and it will behave as if you created a table with the rows you provided.\n```php\n$stateName = State::whereAbbr('NY')->first()->name;\n```\n\nThis is really useful for \"Fixture\" data, like states, countries, zip codes, user_roles, sites_settings, etc...\n\n### Relationships\nLet's say you created a `Role` model, based on an array using Sushi, that looked like this:\n```php\nclass Role extends Model\n{\n    use \\Sushi\\Sushi;\n\n    protected $rows = [\n        ['id' => 1, 'label' => 'admin'],\n        ['id' => 2, 'label' => 'manager'],\n        ['id' => 3, 'label' => 'user'],\n    ];\n}\n```\n\nYou can add a relationship to another standard model, just like you normally would:\n```php\nclass User extends Model\n{\n    ...\n\n    public function role()\n    {\n        return $this->belongsTo(Role::class);\n    }\n}\n```\n\nAssuming the `users` table has a `role_id` column, you can do things like this:\n```php\n\u002F\u002F Grab a User.\n$user = User::first();\n\u002F\u002F Grab a Role.\n$role = Role::whereLabel('admin')->first();\n\n\u002F\u002F Associate them.\n$user->role()->associate($role);\n\n\u002F\u002F Access like normal.\n$user->role;\n\n\u002F\u002F Eager load.\n$user->load('role');\nUser::with('role')->first();\n```\n\n> Note: There is one caveat when dealing with Sushi model relationships. The `whereHas` method will NOT work. This is because the two models are spread across two separate databases.\n\n### Using database-checking validation rules\nYou can even use Laravel's `exists:table,column` database checking request validation rule.\n\n```php\n$data = request()->validate([\n    'state' => ['required', 'exists:App\\Models\\State,abbr'],\n]);\n```\n\n> Note: Be aware that you must use the fully-qualified namespace of the model instead of a table name. This ensures that Laravel will correctly resolve the model's connection.\n\n### Custom Schema\nIf Sushi's schema auto-detection system doesn't meet your specific requirements for the supplied row data, you can customize them with the `$schema` property or the `getSchema()` method.\n\n```php\nclass Products extends Model\n{\n    use \\Sushi\\Sushi;\n\n    protected $rows = [\n        ['name' => 'Lawn Mower', 'price' => '226.99'],\n        ['name' => 'Leaf Blower', 'price' => '134.99'],\n        ['name' => 'Rake', 'price' => '9.99'],\n    ];\n\n    protected $schema = [\n        'price' => 'float',\n    ];\n}\n```\n\n## Advanced Usage\n\nWhen you need more flexibility, you can implement the `afterMigrate(BluePrint $table)` method, allowing you to customize the table after it has been created. This might be useful for adding indexes to certain columns.\n\n```php\nclass Products extends Model\n{\n    use \\Sushi\\Sushi;\n\n    protected $rows = [\n        ['name' => 'Lawn Mower', 'price' => '226.99'],\n        ['name' => 'Leaf Blower', 'price' => '134.99'],\n        ['name' => 'Rake', 'price' => '9.99'],\n    ];\n\n    protected function afterMigrate(Blueprint $table)\n    {\n        $table->index('name');\n    }\n}\n```\n\n## How It Works\nUnder the hood, this package creates and caches a SQLite database JUST for this model. It creates a table and populates the rows. If, for whatever reason, it can't cache a .sqlite file, it will default to using an in-memory sqlite database.\n\n## Using ->getRows()\nYou can optionally opt out of using the `protected $rows` property, and directly implement your own `getRows()` method.\n\nThis will allow you to determine the rows for the model at runtime. You can even generate the model's rows from an external source like a third-party API.\n\n\n```php\nclass Role extends Model\n{\n    use \\Sushi\\Sushi;\n\n    public function getRows()\n    {\n        return [\n            ['id' => 1, 'label' => 'admin'],\n            ['id' => 2, 'label' => 'manager'],\n            ['id' => 3, 'label' => 'user'],\n        ];\n    }\n}\n```\n\n### Caching ->getRows()\n\nIf you choose to use your own ->getRows() method, the rows will NOT be cached between requests by default.\n\nYou can force Sushi to cache your dataset with the following method: `sushiShouldCache()`.\n\nLet's look at a configuration where `->getRows()` datasets would be cached as an example:\n\n```php\nclass Role extends Model\n{\n    use \\Sushi\\Sushi;\n\n    public function getRows()\n    {\n        return [\n            ['id' => 1, 'label' => 'admin'],\n            ['id' => 2, 'label' => 'manager'],\n            ['id' => 3, 'label' => 'user'],\n        ];\n    }\n\n    protected function sushiShouldCache()\n    {\n        return true;\n    }\n}\n```\n\nBy default, Sushi looks at the \"last modified\" timestamp of your model PHP file and compares it with its internal `.sqlite` cache file. If the model file has been changed more recently than the `.sqlite` cache file, then Sushi will destroy and rebuild the `.sqlite` cache.\nAdditionally, you can configure an external file for Sushi to reference when determining if the cache is up to date or needs to be refreshed.\n\nIf, for example, you are using Sushi to provide an Eloquent model for an external data source file like an `.csv` file, you can use `sushiCacheReferencePath` to force Sushi to reference the `.csv` file when determining if the cache is stale.\n\nFor example:\n\n```php\nclass Role extends Model\n{\n    use \\Sushi\\Sushi;\n\n    public function getRows()\n    {\n        return CSV::fromFile(__DIR__.'\u002Froles.csv')->toArray();\n    }\n\n    protected function sushiShouldCache()\n    {\n        return true;\n    }\n\n    protected function sushiCacheReferencePath()\n    {\n        return __DIR__.'\u002Froles.csv';\n    }\n}\n```\n\nNow, Sushi will only \"bust\" its internal cache if `roles.csv` changes, rather than looking at the `Role.php` model.\n\n### Handling Empty Datasets\nSushi reads the first row in your dataset to work out the scheme of the SQLite table. If you are using `getRows()` and this returns an empty array (e.g an API returns nothing back) then Sushi would throw an error.\n\nIf you would like Sushi to work even if the dataset is empty, you can define your schema in the optional `protected $schema` array.\n\n> Note: If you choose to use your own ->getRows() method, the rows will NOT be cached between requests.\n\n```php\nclass Currency extends Model\n{\n    use \\Sushi\\Sushi;\n\n    protected $schema = [\n        'id' => 'integer',\n        'name' => 'string',\n        'symbol' => 'string',\n        'precision' => 'float'\n    ];\n\n    public function getRows()\n    {\n        return [];\n    }\n}\n```\n\n### Handling String-based Primary Keys\nSushi requires you to add two properties to your model, if it uses a string-based primary key - `$incrementing` and `$keyType`:\n\n```php\nclass Role extends Model\n{\n    use \\Sushi\\Sushi;\n\n    public $incrementing = false;\n\n    protected $keyType = 'string';\n\n    protected $rows = [\n        ['id' => 'admin', 'label' => 'Admin'],\n        ['id' => 'manager', 'label' => 'Manager'],\n        ['id' => 'user', 'label' => 'User'],\n    ];\n}\n```\n\n### Troubleshoot\n\n**ERROR:** `SQLSTATE[HY000]: General error: 1 too many SQL variables`\n\nBy default Sushi uses chunks of `100` to insert your data in the SQLite database. In some scenarios this might hit some SQLite limits.\nYou can configure the chunk size in the model: `public $sushiInsertChunkSize = 50;`\n","Sushi 是一个为 Eloquent 提供的“数组”驱动，使得开发者可以在不使用数据库的情况下利用 Eloquent ORM。其核心功能是通过在模型中添加 `Sushi` trait 和 `$rows` 属性来定义数据行，从而让模型如同操作真实数据库表一样处理这些静态数据。此外，Sushi 支持关系映射、Laravel 的验证规则等功能，但需要注意的是，由于数据存储于内存而非传统数据库中，某些依赖于数据库查询的方法（如 `whereHas`）将不可用。此项目适用于需要快速设置固定或测试数据集而不希望配置完整数据库环境的应用场景，比如预设国家列表、角色权限等。",2,"2026-06-11 03:18:43","top_language"]