在数据透视表中使用uuid时,它会返回具有重复ID的uuid,这是怎么回事?

时间:2018-07-06 16:05:13

标签: php laravel uuid

我正在使用webpatser / laravel-uuid。生成uuid到我的数据透视表中,效果很好,但是问题是每次执行循环时都会重复生成的字符串,我不知道该如何处理。

控制器:

 $data=$request->all();
        foreach($data['batch_id'] as $batch){
        $batch = Batch::find($batch);
        $lead = $data['lead_id'];
        $batch->lead()->attach($lead,["uuid" => Uuid::generate()]);

        $batch_leads = new batch_lead;
        $batch_leads->batch_id=$request->input('batch_id');
        $batch_leads->lead_id=$request->input('lead_id');
        $batch_leads = json_encode($data, true);

型号:

public static function boot()
{
    parent::boot();
    self::creating(function ($model) {
        $model->uuid = (string) Uuid::generate();
    });
}

public function getRouteKeyName()
{
    return 'uuid';
}

数据库图片:enter image description here

0 个答案:

没有答案