gpt4 book ai didi

php - Laravel:2 个文本字段到 1 个数据库记录

转载 作者:行者123 更新时间:2023-11-29 05:17:38 24 4
gpt4 key购买 nike

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

现在我希望将 tag + id 添加到同一列 account_id

例如:

John 在 Invis 工作。

enter image description here

INV-012345 将上传到数据库列account_id

目前它只会上传012345到数据库。

现在的问题是我不知道如何将这两个字段上传到 account_id 列。

HTML/Blade

<div class="form-group  {{ $errors->has('account_id') ? 'has-error' : '' }}">
{!! Form::label('account_id', trans('common.account_id'), ['class' => 'form-label col-sm-3 control-label text-capitalize']) !!}
<div class="col-sm-2">
{!! Form::text('account_id', $user->company->abbreviation, ['class' => 'form-control col-sm-3', 'id' => 'disabledInput', 'disabled']) !!}
</div>
<div class="col-sm-4">
{!! Form::text('account_id', null, ['class' => 'form-control col-sm-9', 'placeholder' => trans('common.account_id') ]) !!}
{!! $errors->first('account_id', '<span class="help-block">:message</span>') !!}
</div>
</div>

Controller

class UserController extends Controller
{
private $user;

public function __construct(User $user,CompaniesController $companies, UserTypeController $userType)
{
$cid = Auth::user()->company_id;

if(Auth::user()->usertype_id == 7)
{
$this->user = $user;
}
else
{
$array_company_ids = $companies->getCompany_ids($cid);
$this->user = $user->whereIn('company_id', $array_company_ids);
}

}

public function index()
{
$users = $this->user->with('company', 'usertype')->get();

return view('user.index', compact('users'));
}

public function show()
{
//
}

public function create(CompaniesController $companies, UserTypeController $userType)
{
$companies = $companies->getCompanies(Auth::user()->company_id);
$usertypes = $userType->getUsertypes();

return view('user.create', ['usertypes' => $usertypes,'companies' => $companies]);
}

public function store(CreateUserRequest $request, User $user)
{
$user->fill($request->all());
$user->password = Hash::make($request->input('password'));
$user->save();
return redirect()->route('user.index');
}

public function edit($user_id, CompaniesController $companies, UserTypeController $userType)
{
$user = $this->user->with('company')->findOrFail($user_id);
$companies = $companies->getCompaniesName(Auth::user()->company_id);
$usertypes = $userType->getUsertypes();

return view('user.edit', ['user' => $user, 'usertypes' => $usertypes, 'companies' => $companies]);
}

public function update($id, CreateUserRequest $request)
{
$user = $this->user->find($id);

$password = $request->input('password');

if($password)
{
$user->fill($request->input())->save();
$user->password = Hash::make($request->input('password'));

$user->save();
}
else
{
$user->fill($request->only('account_id', 'email', 'firstname',
'lastname', 'middlename', 'usertype_id', 'active',
'company_id','title','btw_nr','kvk_nr','bic','iban',
'birthday','mobile','telephone','country','city','postal_code',
'house_nr','street'));

$user->save();
}

if ($request->input('usertype_id') <= Auth::user()->usertype_id)
{
$user->usertype_id = $request->input('usertype_id');

$user->save();
}

$user->update();

return redirect()->route('user.index');
}


public function destroy($user)
{
$user->delete();
return redirect('user');
}

最佳答案

这是在我理解您正在尝试做的事情的情况下。

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

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

{!! 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();

关于php - Laravel:2 个文本字段到 1 个数据库记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30572424/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com