【发布时间】:2017-08-04 11:43:28
【问题描述】:
如何获取具有 name 值的 id 值?
我有这个表格:
<form enctype="multipart/form-data" id="projectclientexist" name="projectclientexist">
@foreach ($clients as $key => $client)
<div class="radio">
<div class="col-md-3">
<label><input type="radio" name="client" value="{{$client->name}}">{{$client->name}}</label>
</div>
</div>
@endforeach
<input type="submit" value="Crear relacion Proyecto-Cliente" id="relationclientexist" name="relationclientexist" class="btn btn-success">
</form>
如何获取具有 name 值的客户端的 id 值?
public function storeProjectsClientsIfExist (Request $request)
{
$client_project->project = new Client_Project();
$client_project->client_id = DB::table('clients')
->where('id', DB::raw("(select max(id) "));
$client_project->project_id = DB::table('projects')
->where('id', DB::raw("(select max(`id`) from projects)"))
->first()
->id;
$client_project->save();
}
非常感谢,如果对代码有任何疑问,可以提问。
【问题讨论】:
-
你能详细说明你的问题吗?
-
当然;)当你在表单上传递名称值时,如何获取客户端的id;)
-
试试这个
$client_project->client_id = DB::table('clients')->where('name', $request('client'))->first()->id;:) ` -
知道为什么当我提交到:web.loc/admin/… ?我认为可能有些 id 是错误的
-
因为你没有在表单和方法中添加提交后点击的路由。