Download the PHP package involix/sushi without Composer
On this page you can find all versions of the php package involix/sushi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download involix/sushi
More information about involix/sushi
Files in involix/sushi
Informations about the package sushi
Sushi 🍣
Eloquent's missing "array" driver.
Sometimes you want to use Eloquent, but without dealing with a database.
This Package Is Sponsorware 💰💰💰
Originally, this package was only available to my sponsors on GitHub Sponsors until I reached 75 sponsors.
Now that we've reached the goal, the package is fully open source.
Enjoy, and thanks for the support! ❤️
Install
Use
Using this package consists of two steps:
- Add the
Sushi
trait to a model. - Add a
$rows
property to the model.
That's it.
Now, you can use this model anywhere you like, and it will behave as if you created a table with the rows you provided.
This is really useful for "Fixture" data, like states, countries, zip codes, user_roles, sites_settings, etc...
Relationships
Let's say you created a Role
model, based on an array using Sushi, that looked like this:
You can add a relationship to another standard model, just like you normally would:
Assuming the users
table has a role_id
column, you can do things like this:
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.
How It Works
Under 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.
Using ->getRows()
You can optionally opt out of using the protected $rows
property, and directly implement your own getRows()
method.
This 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.
Note: If you choose to use your own ->getRows() method, the rows will NOT be cached between requests.
All versions of sushi with dependencies
illuminate/database Version ^5.8 || ^6.0
illuminate/support Version ^5.8 || ^6.0