我使用laravel 5.2框架在php中创建车辆编辑表单,并从mysql数据库中获取值到表单。在表单中使用两个表数据。在表单中,我给出了一个用于组成员身份的下拉列表。该下拉列表中的数据是从数据库中获取的。我需要将该下拉列表作为多选下拉列表。车辆编辑表单中的手段我们可以将该特定车辆分配给多个组。我如何使用laravel 5.2
在php中进行多选我的车辆编辑(查看页面)给出了
@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
}
}
任何人请帮我这样做。回应很明显。
答案 0 :(得分:0)
<select multiple="multiple" name="group[]" id="group">
@foreach($grouplist as $aKey => $group)
@foreach($grouplist->sports as $aItemKey => $grouplist)
<option value="{{$aKey}}" @if($aKey == $aItegrouplistmKey)selected="selected"@endif>{{$group}}</option>
@endforeach
@endforeach
</select