Description
Eloquent's missing "array" driver. Sometimes you want to use Eloquent, but without dealing with a database.
Install
composer require calebporzio/sushi
Use
Using this package consists of two steps:
- Add the
Sushitrait to a model. - Add a
$rowsproperty to the model.
That's it.
class State extends Model{ use \Sushi\Sushi; protected $rows = [ [ 'abbr' => 'NY', 'name' => 'New York', ], [ 'abbr' => 'CA', 'name' => 'California', ], ];}
Now, you can use this model anywhere you like, and it will behave as if you created a table with the rows you provided.
$stateName = State::whereAbbr('NY')->first()->name;
This is really useful for "Fixture" data, like states, countries, zip codes, user_roles, sites_settings, etc...
Recent Courses on Laravel Daily
Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
Testing in Laravel 13 For Beginners
26 lessons
1 h 41 min read
How to Structure Laravel 13 Projects
16 lessons
1 h 32 min read