如何獲取具有名稱值的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