I have this Cluster_Members model
<?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');
}
}
Then i have check in my view that has name of client_id[]
In my controller. I want to insert it once and detect if the cluster_id and client_id is not existing on that table.
Any suggestion on how to do it without looping like this?
$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]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire