Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel:将2个文本字段合并到1个数据库记录中_Php_Mysql_Laravel - Fatal编程技术网

Php Laravel:将2个文本字段合并到1个数据库记录中

Php Laravel:将2个文本字段合并到1个数据库记录中,php,mysql,laravel,Php,Mysql,Laravel,我有一个表格可以编辑公司的用户。 我得到了一个公司的禁用字段(用户添加到该公司)和一个帐户id为的字段 现在我想将标记+id添加到同一列account\u id 例如: 约翰在英维斯工作 INV-012345将上载到数据库列帐户id 到目前为止,它只会将012345上传到数据库 现在的问题是,我不知道如何将这两个字段上载到account\u id列 HTML/Blade {!!Form::label('account_id',trans('common.account_id'),['clas

我有一个表格可以编辑公司的用户。 我得到了一个公司的
禁用字段
(用户添加到该公司)和一个帐户id为
的字段

现在我想将
标记
+
id
添加到同一列
account\u id

例如:

约翰在英维斯工作

INV-012345
将上载到数据库列
帐户id

到目前为止,它只会将
012345
上传到数据库

现在的问题是,我不知道如何将这两个字段上载到
account\u id

HTML/Blade


{!!Form::label('account_id',trans('common.account_id'),['class'=>'Form label col-sm-3 control label text capitalize'])
{!!Form::text('account_id',$user->company->缩写,['class'=>'表单控件col-sm-3','id'=>'禁用输入','禁用'])
{!!Form::text('account_id',null,['class'=>'Form control col-sm-9','placeholder'=>trans('common.account_id'))
{!!$errors->first('account_id',':message')!!}
控制器

类UserController扩展控制器
{
私人用户;
公共函数构造(用户$User,公司控制器$companys,用户类型控制器$userType)
{
$cid=Auth::user()->公司id;
if(Auth::user()->usertype_id==7)
{
$this->user=$user;
}
其他的
{
$array\u company\u id=$companys->getCompany\u id($cid);
$this->user=$user->其中('company\u id',$array\u company\u id);
}
}
公共职能指数()
{
$users=$this->user->with('company','usertype')->get();
返回视图('user.index',压缩('users');
}
公共活动展览(
{
//
}
创建公共函数(companyescontroller$companys,UserTypeController$userType)
{
$companys=$companys->getcompanys(Auth::user()->company\u id);
$usertypes=$userType->getUsertypes();
返回视图('user.create',['usertypes'=>$usertypes,'companys'=>$companys]);
}
公共函数存储(CreateUserRequest$request,User$User)
{
$user->fill($request->all());
$user->password=Hash::make($request->input('password');
$user->save();
return redirect()->route('user.index');
}
公共函数编辑($user\u id,companyescontroller$companys,UserTypeController$userType)
{
$user=$this->user->with('company')->findOrFail($user\u id);
$companys=$companys->getcompanyesname(Auth::user()->company\u id);
$usertypes=$userType->getUsertypes();
返回视图('user.edit',['user'=>$user,'usertypes'=>$usertypes,'companys'=>$companys]);
}
公共函数更新($id,CreateUserRequest$request)
{
$user=$this->user->find($id);
$password=$request->input('password');
如果($password)
{
$user->fill($request->input())->save();
$user->password=Hash::make($request->input('password');
$user->save();
}
其他的
{
$user->fill($request->only('account\u id','email','firstname',
“lastname”、“middlename”、“usertype\u id”、“active”,
‘公司id’、‘头衔’、‘顺便说一句’、‘kvk’、‘bic’、‘iban’,
“生日”、“手机”、“电话”、“国家”、“城市”、“邮政编码”,
"住宅","街道";;
$user->save();
}
if($request->input('usertype\u id')usertype\u id)
{
$user->usertype_id=$request->input('usertype_id');
$user->save();
}
$user->update();
return redirect()->route('user.index');
}
公共功能销毁($user)
{
$user->delete();
返回重定向(“用户”);
}

如果我理解你的意图,我会这么做

您需要分解正在保存的内容,并将数据的两部分连接起来

首先,在刀片中,将它们作为单独的表单字段,例如

{!! Form::text('account_id') !!}
{!! Form::text('tag') !!}
运行函数更新用户时使用此选项

$user = $this->user->find($id);

$user->account_id = $request['tag']."-".$request['account_id'];

//Insert all other fields here e.g.
$user->email = $request['email'];

//To save the data use
$user->save();

这正是您现在拥有的,但它似乎没有发送带有帐户id部分的标记。对于这个特定示例,如果我添加($user),它只会发送
-012345
。如果没有添加,我将获得
SQLSTATE[42S22]:未找到列:1054“字段列表”中的未知列“缩写”(SQL:update
users'set
account\u id
=T1233123123,
update\u于
=2015-06-02 09:30:12,
缩写
=其中
id
=9)`好的,它现在可以工作了。唯一的问题是,现在它将提供
INV
INV-12345
,因为它将获得帐户id,所以我需要拆分前4个字符。好的,你能粘贴整个过程中的代码吗?我知道了!谢谢你的帮助。
{!! Form::text('account_id') !!}
{!! Form::text('tag') !!}
$user = $this->user->find($id);

$user->account_id = $request['tag']."-".$request['account_id'];

//Insert all other fields here e.g.
$user->email = $request['email'];

//To save the data use
$user->save();