我想要一個具有 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
....
這將是資料,存盤在模型檔案中,就好像它是一個資料庫表一樣,但永遠不能改變。這可能嗎?
uj5u.com熱心網友回復:
你可以使用壽司。
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'
],
];
}
https://github.com/calebporzio/sushi
uj5u.com熱心網友回復:
我認為您可以使用一個簡單的模型,而無需創建用于注入資料的表單,并在第一次(運行遷移時)使用播種機來包含您的資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/367079.html
