[英]how to input 2 value from each column to one column in another table
i try to input value of first_name and last_name from table students to column name of table users here is my studentcontroller我尝试从表学生输入名字和姓氏的值到表用户的列名这是我的学生控制器
public function store(Request $request)
{
$user = new User;
$user->name = $request->first_name&&$request->last_name;
$user->save();
$student = new Santri;
$student->user_id = $user->id;
$student->first_name = $request->get('first_name');
$student->last_name = $request->get('last_name');
$student->save();
return redirect()->route('student.index');
}
then the result value='1' in column name at table user然后在表用户的列名中的结果值='1'
how to get value first_name and last_name sorted to column name in table user?如何将值 first_name 和 last_name 排序到表用户中的列名?
Don't use &&, use php's concatenation operator.不要使用 &&,使用 php 的连接运算符。
$user->name = $request->first_name . $request->last_name;
The reason why you're getting 1 as a result is because you're using the && Logical operator.结果得到 1 的原因是因为您使用的是 && 逻辑运算符。 Because php is very weakly typed it assumes anything that isn't a null or a 0 is "True", and by comparing "True" && "True" you get "True" which is 1
因为 php 的类型非常弱,它假定任何不是 null 或 0 为“真”,通过比较“真”&&“真”你得到“真”,即 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.