我有一個這樣的陣列,它有它如何在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 –