如何获取具有名称值的id值?获取表单上具有其他值的行的ID Laravel
我有这样的形式:
<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>
我该怎么办呢取值,其命名为价值客户的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;':) ' – Maraboc