php - Array to string conversion in laravel 5.4 , controllers -
i'm getting array conversion error while inserting multiple data , code mentioned below please take , me
controller.php
if(!empty($value)) { foreach ($value $v) { $insert[] = ['name' => $v['name'], 'email' => $v['email'],'company_name' => $v['company_name'],'company_id' => $v['company_id'], 'emp_id' => $v['emp_id']]; $role_id= $v['role_id']; $name=$v['name']; $email=$v['email']; $emails[]=$v['email']; $emp_id=$v['emp_id']; $data = array( 'name' => $name,'email' => $email , 'emp_id' => $emp_id); $roles[]= $v['role_id']; } } } if(!empty($insert)) { $inserted=user::insert($insert); if($inserted) { $email_select=user::select('id')->wherein('email',$emails)->where('company_id',auth::user()->company_id)->orderby('id','asc')->get(); foreach ($email_select $key => $idget) { $getid[]=$idget->id; } } $datas[]=['user_id' => $getid , 'role_id' => $roles]; $insert_role=db::table('role_user')->insert($datas) ;
i'm getting error called array string conversion while insert_role variable execution
(2/2) queryexception array string conversion (sql: insert
role_user
(role_id
,user_id
) values (1, 16))
$roles
, $getid
both arrays. guessing want assign roles selected mail addresses. have following:
if($inserted) { $email_select=user::select('id')->wherein('email',$emails)->where('company_id',auth::user()->company_id)->orderby('id','asc')->get(); foreach ($email_select $key => $idget) { foreach($roles $role) { $datas[] = ['user_id' => $idget->id, 'role_id' => $role]; } } } $insert_role=db::table('role_user')->insert($datas);
i think should work.
Comments
Post a Comment