![](/img/trans.png)
[英]fetch value from table and update second table in same controller in laravel
[英]how to fetch value from one table and insert into second table while inserting data to the second table as backend function. using laravel 5.2
我有两个表,一个是account
,另一个是user
。
在account
表中, accountID
是主键。
uerID是“用户”表中的一列。 当我向user
表中插入userID
值时, account
表中的accountID
值应以隐藏的形式插入到“用户”表中(列名称本身就是accountID)。由于我们插入userID时,我们不提供任何输入accountID的选项再次。 它将自动从“帐户”表中获取。 在帐户表中包含单个数据。
public function userInsert(Request $request)
{
$postUser = Input::all();
$account = Account::select('accountID')->get();
/* $data=DB::table('account')
->select("accountID"); */
//insert data into mysql table
$data = array('accountID'=>$account['accountID'],
'userID'=> $postUser['userID']
);
// echo print_r($data);
$ck = 0;
$ck = DB::table('user')->Insert($data);
//echo "Record Added Successfully!";
$name = DB::table('user')->simplePaginate(10);
return view('user.userAdmin')->with('name', $name);
}
以上是给插入功能创建新的用户ID
如何在laravel 5.2中编写sql查询以执行此操作?
任何人都可以帮助我,答复是明显的..!
据我了解,您想将accountID
添加到user
表中。 您应该能够通过简单地将accountID
添加到数组中来插入该accountID
。
$postUser = Input::all();
$account = Account::select('accountID')->get();
// Add the value of the accountID to the post array
$data = array("accountID" => $account['accountID'],
"userID"=> $postUser['userID']
);
// echo print_r($data);
$ck = 0;
$ck = DB::table('user')->Insert($data);
//echo "Record Added Successfully!";
$name = DB::table('user')->simplePaginate(10);
return view('user.userAdmin')->with('name', $name);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.