Eloquent’s missing “array” driver
Sometimes you just want to use Laravel Eloquent without a database.
Caleb Porzio
A project from
Caleb Porzio
Try it
1
Install
Require the composer package in your Laravel project.
composer require calebporzio/sushi
2
Add the trait
Add the Sushi trait to your Eloquent model.
class State extends Model { use \Sushi\Sushi; }
3
Add property
Add a $rows property to the model.
class State extends Model { use \Sushi\Sushi; protected $rows = [ [ 'abbr' => 'NY', 'name' => 'New York', ], [ 'abbr' => 'CA', 'name' => 'California', ], ]; }
4
Done!
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;
My other projects
The most productive way to build your next web app
Powerful, dynamic, front-end UIs without leaving PHP.
+20k Github Stars
Visit the website
Alpine.js
Simple. Lightweight.
Powerful as hell.
Your new, lightweight, JavaScript framework.
+24k Github Stars
Visit the website