发生超时时,Laravel会插入两次数据

时间:2018-02-10 02:16:01

标签: php laravel timeout laravel-5.5

我注意到laravel在发生超时时重新执行插入操作

当超时错误触发时,如何通过退休来购买它以再次插入数据?

foreach ($comments_data as $comment_data)
                {
                    if ( ! empty($comment_data['date']))
                    {

                        $total_rating[] = $this->check_rating_value($comment_data['rating']);
                        $comment_id     = ( new Comment() )->saveComments($shop, $comment_data, $product_id, $urls, $shop_options);


                        ( new Comments_images() )->save_images($comment_id, $shop, $comment_data['images']);
                    }

                }

插入代码

public function saveComments($shop, $comments_data, $product_id, $url, $shop_options)
{
    $date = Carbon::parse($comments_data['date']);

    if ($shop_options->filter_status == 1)
    {
        $comments = str_replace(explode(',', $shop_options->filter_find_words), explode(',', $shop_options->filter_alter_words), $comments_data['comment']);
    } else
    {
        $comments = $comments_data['comment'];
    }

    $faker             = Factory::create();
    $this->shop_name   = $shop;
    $this->comment     = $comments;
    $this->rating      = $this->check_rating_value($comments_data['rating']);
    $this->product_id  = $product_id;
    $this->user_name   = $faker->userName;
    $this->product_url = $url;
    $this->created_at  = $date->toDateTimeString();
    $this->country     = $comments_data['country'] == 'IL' ? 'PS' : $comments_data['country'];
    $this->view        = 1;
    $this->save();

    return $this->id;
}

0 个答案:

没有答案