2016-09-19 95 views
0

我正在php中使用laravel 5.2框架創建車輛編輯表單,並從mysql數據庫中將值提取到表單中。在表格中使用兩個表格數據。在表單中,我正在給出一個組成員的下拉列表。該下拉列表中的數據是從數據庫中提取的。我需要將下拉列表作爲多選下拉列表。在車輛編輯表單中,我們可以將該特定車輛分配給多個組。我該怎麼辦使用laravel在PHP中,這多選擇5.2如何使用php laravel 5.2多重選擇選項

我的車編輯(查看頁面)得到下述

@extends('app') 

@section('content') 
    <br><br><br><br><br> 
    <div class="templatemo-content-wrapper"> 
     <div class="container"> 
      <ol class="breadcrumb"> 
       <li><a href="{{ url("/") }}"><font color="green">Home</font></a></li> 
       <li class="active">View/Edit Vehicle</li> 
      </ol> 
      <div class="row"> 
       <div class="col-md-8 col-md-offset-2"> 
        <div class="panel panel-success"> 
         <div class="panel-heading">View/Edit Vehicle Information</div> 
         <div class="panel-body"> 
          @if (count($errors) > 0) 
           <div class="alert alert-danger"> 
            <strong>Whoops!</strong> There were some problems with your input.<br><br> 
            <ul> 
             @foreach ($errors->all() as $error) 
              <li>{{ $error }}</li> 
             @endforeach 
            </ul> 
           </div> 
          @endif 

          <form class="form-horizontal" role="form" method="POST" action="{{ url('vehicle/update/') }}"> 
           <input type="hidden" name="_token" value="{{ csrf_token() }}"> 
@foreach($devices as $device) 
           <div class="form-group"> 
            <label class="col-md-4 control-label">Vehicle ID</label> 
            <div class="col-md-6"> 

             <input type="text" class="form-control" name="deviceID" value="{{ ($device->deviceID)}}"> 

            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Creation date</label> 
            <div class="col-md-6"> 

             <input type="text" class="form-control" name="creationTime" value="{{ date('Y/m/d H:i:s',($device->creationTime))}}"> 

            </div> 
           </div> 

           <!--<div class="form-group"> 
            <label class="col-md-4 control-label">Server ID</label> 
            <div class="col-md-6"> 

             <input type="text" class="form-control" name="userID" value="" placeholder="Enter User ID"> 

            </div> 
           </div> --> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Unique ID</label> 
            <div class="col-md-6"> 

             <input type="text" class="form-control" name="uniqueID" value="{{ ($device->uniqueID)}}" placeholder="Enter Unique ID"> 

            </div> 
           </div> 


           <div class="form-group"> 
            <label class="col-md-4 control-label">Active</label> 
            <div class="col-md-6"> 
             <select class="form-control" value="{{ ($device->isActive) }}" name="isActive" > 
              <option value="1">Yes</option> 
              <option value="0">No</option> 
             </select> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Vehicle Description</label> 
            <div class="col-md-6"> 
             <input type="text" class="form-control" name="description" value="{{ ($device->description) }}" placeholder="Enter the description"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Short Name</label> 
            <div class="col-md-6"> 
             <input type="text" class="form-control" name="displayName" value="{{ ($device->displayName) }}" placeholder="Enter Display Name"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Vehicle ID</label> 
            <div class="col-md-6"> 
             <input type="text" class="form-control" name="vehicleID" value="{{ ($device->vehicleID) }}" placeholder="Enter Vehicle ID"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">License Plate</label> 
            <div class="col-md-6"> 
             <input type="text" class="form-control" name="licensePlate" value="{{ ($device->licensePlate) }}" placeholder="Enter license Plate"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">License Expiration</label> 
            <div class="col-md-6"> 
             <input type="date" class="form-control" name="licenseExpire" value="{{ ($device->licenseExpire) }}" placeholder="Enter license Expire Date"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Equipment Type</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="equipmentType" value="{{ ($device->equipmentType) }}" placeholder="Enter E-Mail Address"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Equipment Status</label> 
            <div class="col-md-6"> 
             <select class="form-control" value="{{ ($device->equipmentStatus) }}" name="equipmentStatus" > 
              <option>Unspecified</option> 
              <option value="inservice">In Service</option> 
              <option value="rented">Rented</option> 
              <option value="pending">Pending</option> 
              <option value="completed">Completed</option> 
              <option value="available">Available</option> 
              <option value="unavailable">Unavailable</option> 
              <option value="repair">Repair</option> 
              <option value="retired">Retired</option> 

             </select> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">IMEI/EDN Number</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="imeiNumber" value="{{ ($device->imeiNumber) }}" placeholder="Enter IMEI/EDN Number"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Serial Number</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="serialNumber" value="{{ ($device->serialNumber) }}" placeholder="Enter Serial Number"> 
            </div> 
           </div> 

          <!-- <div class="form-group"> 
            <label class="col-md-4 control-label">Data Key</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address"> 
            </div> 
           </div> --> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">SIM Phone</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="simPhoneNumber" value="{{ ($device->simPhoneNumber) }}" placeholder="Enter SIM Phone Number"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">SMS Email Address</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="smsEmail" value="{{ ($device->smsEmail) }}" placeholder="Enter SMS E-Mail Address"> 
            </div> 
           </div> 

          <!-- <div class="form-group"> 
            <label class="col-md-4 control-label">Group Pushpin ID</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address"> 
            </div> 
           </div> --> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Map Route Color</label> 
            <div class="col-md-6"> 
             <select class="form-control" value="{{ ($device->displayColor) }}" name="displayColor" > 
              <option>Default</option> 
              <option value="#000000">Black</option> 
              <option value="#a52a2a">Brown</option> 
              <option value="#dd0000">Red</option> 
              <option value="#b37400">Orange</option> 
              <option value="#008f00">Green</option> 
              <option value="#0000ee">Blue</option> 
              <option value="#9400d3">Purple</option> 
              <option value="#505050">Grey</option> 
              <option value="#00b3b3">Cyan</option> 
              <option value="#ff1493">Pink</option> 
              <option value="none">None</option> 
             </select> 
            </div> 
           </div> 




           <div class="form-group"> 
            <label class="col-md-4 control-label">Fuel Capacity</label> 
            <div class="col-md-6"> 
             <input type="text" class="form-control" name="fuelCapacity" value="{{ ($device->fuelCapacity) }}" > 
            </div> 
           </div> 


           <div class="form-group"> 
            <label class="col-md-4 control-label">Driver ID</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="driverID" value="{{ ($device->driverID) }}"> 
            </div> 
           </div> 

         <!--  <div class="form-group"> 
            <label class="col-md-4 control-label">Reported Odometer</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address"> 
            </div> 
           </div> 

           <div class="form-group"> 
            <label class="col-md-4 control-label">Reported Engine Hours</label> 
            <div class="col-md-6"> 
             <input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address"> 
            </div> 
           </div> --> 

            <div class="form-group"> 

              <label class="col-md-4 control-label">Group Membership</label> 
              <div class="col-md-6"> 
              <select class="form-control" value="{{ old('groupID') }}" name="groupID" > 
               @foreach($grouplist as $group) 
                @if ($group->groupID == old('description')) 
                 <option value="{{ $group->groupID }}" selected[]>{{ $group->groupID." ".'['.$group->description.']' }}</option> 
                @else 
                 <option value="{{ $group->groupID }}" >{{ $group->groupID." ".'['.$group->description.']' }}</option> 
                @endif 
               @endforeach 
              </select> 
               </div> 
             </div> 




           <div class="form-group"> 
            <div class="col-md-6 col-md-offset-4"> 
             <button type="submit" class="btn btn-warning"> 
              Update 
             </button> 
            </div> 
           </div> 
@endforeach 
          </form> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
@endsection 

和控制器頁面

public function edit($id) 
{ 
    try { 
     //Find the vehicle object from model if it exists 
     $grouplist = Map::select('groupID','description')->get(); 


     $devices = DB::table('device')->where('deviceID', '=', $id)->get(); 

     //Redirect to edit vehicle form with the user info found above. 
     return view('vehicle.add')->with(['devices'=>$devices,'grouplist'=>$grouplist]); 
     // return view('vehicle.add')->with('devices', $devices)->with('grouplist',$grouplist); 


    } catch (ModelNotFoundException $err) { 
     //redirect to your error page 
    } 
} 

請人幫我做這個。迴應是可觀的。

+1

在選擇標籤中添加'multiple'來爲前者做多重選擇。 '