1 回答

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