我有 Cluster_Members 模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Cluster_Members extends Model
{
protected $table ='cluster_members';
protected $fillable=['client_id','cluste_id'];
public function name(){
return $this->belongsTo('App\Client_Information','client_id');
}
}
然后我检查了我的视图,其名称为 client_id []
在我的控制器中。我想插入一次并检测该表上是否存在cluster_id和client_id。
关于如何在没有这样循环的情况下做任何建议?
$cluster_members = new \App\Cluster_Members;
$cluster_id= $request->id
foreach($request->client_id as $x){
$cluster_members::Create(['cluster_id'=>$cluster_id,'client_id'=>$x]);
}