我有一个这样的阵列,它有它如何在Laravel中使用firstOrCreate将数组插入数据库?
`array (size=120)
0 =>
array (size=8)
'name' => That the quick brown fox jumps over the lazy - 7' (length=53)
'url' => string 'google.com/zyx' (length=134)
'category' => string 'search-engine' (length=6)
1 =>
array (size=8)
'name' => string 'Mr. john brandy gave me a wall nut of quite' (length=67)
'url' => string 'yahoo.com/dzxser' (length=166)
'category' => string 'indian' (length=6)`
我想将它们插入到我已经创建了模型,我的书签表120元,我要确保复制不会发生。我发现这个https://laravel.com/docs/5.4/eloquent#other-creation-methods特别是firstOrCreate
方法。
我假设我必须使用foreach,但我不知道如何。任何人都可以帮助我解决一些问题。
在这里没有任何副本 –
@AbdullaNilam我知道,但它是一个只有2个元素的例子。我告诉它总共包含120个元素,或者可能包含更多元素。 – coolsaint
检查这个http://laravel-tricks.com/tricks/using-eloquentfirstorcreate-to-prevent-duplicate-seeding和这个https://laracasts.com/discuss/channels/laravel/first-or-create-result –