我有表格,我正在使用表單模型綁定。我的形式是Laravel 5如何將2個模型傳遞給表單
{!! Form::model($vehicle,['url' => '/pages/store']) !!}
<table style="width:650px; margin-left: 4px;" >
<tbody>
<tr>
<td>ID</td>
<td>Model</td>
<td>Brand</td>
<td>License Plate</td>
</tr>
<tr>
<td>{!! Form::text('id' ,null , ['readonly'], ['class' =>'textboxlong form-control', 'style'=>'height:23px;']) !!}</td>
<td>{!! Form::text('model' ,null ,['class' =>'textboxlong form-control', 'style'=>'height:23px;']) !!}</td>
<td>
{!! Form::select('brand_id', $brands, null, ['id'=>'brandBox', 'style' => 'width:150px;']) !!}
</td>
<td>{!! Form::text('licenseplate' ,null ,['class' =>'textboxlong form-control', 'style'=>'height:23px;']) !!}</td>
</tr>
<tr>
<td colspan="2">Client</td>
</tr>
<tr>
<td colspan="2">{!! Form::select('representive_client_id', $clients, null, ['id'=>'clientSelectBox', 'class' => 'selectbox']) !!}</td>
</tr>
<tr>
<td colspan="2">Telephone Number</td>
</tr>
<tr>
<td colspan="2">{!! Form::text('tel_number' ,null ,['class' =>'textboxlong form-control', 'style'=>'height:23px;']) !!}</td>
</tr>
<tr>
<td colspan="2">Adress</td>
<td colspan="2">{!! Form::textarea('address' ,null ,['class' =>'textboxlong form-control','style'=>'height:60px;']) !!}</td>
</tr>
</tbody>
</table>
<div id="buttoncontainer">
<a class="btn btn-default" href="{{ URL::to('pages/vehicleprocess/' . $first -> id) }}"><<</a>
@if($previous)
<a class="btn btn-default" href="{{ URL::to('pages/vehicleprocess/' . $previous) }}">PREVIOUS</a>
@endif
@if($next)
<a class="btn btn-default" href="{{ URL::to('pages/vehicleprocess/' . $next) }}">NEXT</a>
@endif
<a class="btn btn-default" href="{{ URL::to('pages/vehicleprocess/' . $last -> id) }}">>></a>
<a class="btn btn-default" id="add">EKLE</a>
{!! Form::submit('EDIT', array('class'=>'btn btn-primary')) !!}
{!! Form::submit('NEW RECORD', array('class'=>'btn btn-primary')) !!}
</div>
{!! Form::close() !!}
我傳遞的$vehicle
作爲
$vehicle = Vehicle::where('vehicles.id',$id)->join('clients', 'vehicles.representive_client_id', '=', 'clients.id')->first();
存儲功能
$client = new Client;
$client -> full_name = $client_id;
$client -> tel_number = $tel_number;
$client -> mobile_number = $mobile_number;
$client -> save();
$last_client_id = $client -> id;
$input = Request::except('client_id');
$vehicle = Vehicle::create($input);
$u_vehicle = Vehicle::orderBy('created_at', 'desc')->first();
$u_vehicle -> update(array('client_id' => $last_client_id));
我能夠看到在我看來這些領域的所有值,但是當涉及到存儲新紀錄到我的數據庫我得到這個錯誤
列沒有找到未知列「tel_number」
想我需要通過2種型號(車輛和客戶端)的形式,但不知道如何做到這一點。任何幫助,將不勝感激。
請提供您嘗試存儲車輛時的代碼。如果您嘗試更新車輛關係,則無需將兩個模型傳遞給您可以通過關係更新的視圖:http://laravel.com/docs/5.1/eloquent-relationships#inserting-related-models – haakym
@ haakym我需要通過使用這種形式更新車輛和客戶端 – Tartar
當然,我假設他們是相關的 - 對不對?您可以使用試圖將模型存儲在數據庫中的代碼編輯/更新您的問題,我很樂意提供幫助。這是導致錯誤的代碼。謝謝。 – haakym