1 回答

TA貢獻1773條經驗 獲得超3個贊
這正是firstOrCreate()
可以用來做的事情。
Model::firstOrCreate( ['number' => $num], ['another' => $another] );
會找到一個模型['number' => $num]
,其中 ,如果沒有找到,它將創建一個新模型['number' => $num]
和 ['another' => $another]
https://laravel.com/docs/7.x/eloquent#other-creation-methods
- 1 回答
- 0 關注
- 120 瀏覽
添加回答
舉報