php - Laravel 5 How to Pass 2 Models to a Form -


i have form , using form model binding. form is

{!! 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>&nbsp;         @if($previous)             <a class="btn btn-default" href="{{ url::to( 'pages/vehicleprocess/' . $previous ) }}">previous</a>&nbsp;         @endif         @if($next)         <a class="btn btn-default" href="{{ url::to( 'pages/vehicleprocess/' . $next ) }}">next</a>&nbsp;         @endif         <a class="btn btn-default" href="{{ url::to( 'pages/vehicleprocess/' . $last -> id ) }}">>></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;         <a class="btn btn-default" id="add">ekle</a>&nbsp;         {!! form::submit('edit', array('class'=>'btn btn-primary')) !!}&nbsp;         {!! form::submit('new record', array('class'=>'btn btn-primary')) !!}&nbsp;     </div> {!! form::close() !!} 

i passing $vehicle as

$vehicle = vehicle::where('vehicles.id',$id)->join('clients', 'vehicles.representive_client_id', '=', 'clients.id')->first(); 

store function

$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)); 

i able see values of these fields in view when comes store new record database getting error

column not found unknown column 'tel_number'

guess need pass 2 models (vehicle , client) form not sure how make it. appreciated.

in short need pass view instance of vehicle client - know you're trying join i'm guessing isn't right way it. set clean install laravel , appears work when set relationship on model.

i'm unsure relationships let's assume client has 1 vehicle vehicle belongs client. can put relationship in vehicle.php

public function client() {    return $this->belongsto('app\client'); // or whatever namespace class } 

see more here on defining relationships: http://laravel.com/docs/5.1/eloquent-relationships#defining-relationships

then when load model in view can this:

$vehicle = \app\vehicle::with('client')->where('id', $id)->first(); 

the important part being: with('client')

then text fields client attributes should populated existing data.

i hope helps, if need more please let me know. i've got sample code of working in blank laravel project can throw on github if need see it.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -