我可以拥有没有数据库表的 Laravel 模型吗?

Ron*_*her 6 php laravel eloquent

我想要一个具有 Laravel 模型的所有特性和功能的 Laravel 模型,但模型的数据是完全静态的并且永远不会改变。我可以为其创建一个数据库表,但这留下了有人直接修改该表的可能性。

例如:

    //  Model Data for Log Levels
    name      | icon                | color
    -------------------------------------------
    Emergency | fas fa-ambulance    | red
    Alert     | fas fa-bullhorn     | yellow
    Critical  | fas fa-heartbeast   | orange
    ....
Run Code Online (Sandbox Code Playgroud)

这将是存储在模型文件中的数据,就像数据库表一样,但永远无法更改。这可能吗?

Mic*_*vec 10

您可以使用寿司

Eloquent 缺少“数组”驱动程序。

有时您想使用 Eloquent,但不处理数据库。

class State extends Model
{
    use \Sushi\Sushi;

    protected $rows = [
        [
            'name' => 'Emergency',
            'icon' => 'fas fa-ambulance',
            'color' => 'red'
        ],
        [
            'name' => 'Alert',
            'icon' => 'fas fa-bullhorn',
            'color' => 'yellow'
        ],
        [
            'name' => 'Critical',
            'icon' => 'fas fa-heartbeast',
            'color' => 'orange'
        ],
    ];
}
Run Code Online (Sandbox Code Playgroud)

https://github.com/calebporzio/sushi