Eloquent 使用 firstOrCreate 函数批量插入 MySQL?

Eloquent Bulk insert in MySQL using firstOrCreate function?

如何使用 Laravel 上的 firstOrCreate 函数批量插入 MySQL?我正在通过 RESTfull API

发送数据

我的模特:

{
    "hashtags": [{
            "text": "hashtag1"
        }, {
            "text": "hashtag2"
        }, {
            "text": "hashtag3"
        }, {
            "text": "hashtag4"
        }, {
            "text": "hashtag5"
        }
    ]
}

当我将此模型传递给 firstOrCreate 函数时,

$hashtag_data = $request->get('hashtags');
$hashtags = Hashtag::firstOrCreate($hashtag_data);

它returns错误。

但是当我通过特定记录时

$hashtag_data = $request->get('hashtags');
$hashtags = Hashtag::firstOrCreate($hashtag_data[1]);

插入成功

下面应该可以,但不能在机器上测试。

   $hashtag_data = $request->get('hashtags');
   $hashtags = Hashtag::insert($hashtag_data);