私のフォームでは、複数選択ドロップダウンリストを作成しました。私は私のマルチ選択ドロップダウンからデータベース、テーブル名devicelistと私のフォームから取得されたいくつかの値を選択したデータを格納する必要があります。 私のビューページは複数選択ドロップダウンデータをデータベースに挿入する方法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" multiple >--}}
{{[email protected]($grouplist as $group)--}}
{{[email protected] ($group->groupID == old('description'))--}}
{{--<option value="{{ $group->groupID }}" >{{ $group->groupID." ".'['.$group->description.']' }}</option>--}}
{{[email protected]}}
{{--<option value="{{ $group->groupID }}" >{{ $group->groupID." ".'['.$group->description.']' }}</option>--}}
{{[email protected]}}
{{[email protected]}}
{{--</select>--}}
<script type="text/javascript">
$(".js-example-basic-multiple").select2();
</script>
<select class="js-example-basic-multiple js-states form-control" id="id_label_multiple" value="{{ old('groupID[]') }}" name="groupID" multiple="multiple" >
@foreach($grouplist as $group)
@if ($group->groupID == old('description'))
<option value="{{ $group->groupID }}" >{{ $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 update(Request $request)
{
try {
$postUser = Input::all();
//insert data into mysql table
$account = Account::select('accountID')->where('accountID', '=', 'gts')->get();
foreach ($account as $acc) {
$abc = $acc->accountID;
}
$data=DB::table('device')
->where("deviceID",$request['deviceID'])
->update(array(
"uniqueID"=>$request['uniqueID'],
"isActive"=>$request['isActive'],
"description"=>$request['description'],
"displayName"=>$request['displayName'],
"vehicleID"=>$request['vehicleID'],
"licensePlate"=>$request['licensePlate'],
"licenseExpire"=>$request['licenseExpire'],
"equipmentType"=>$request['equipmentType'],
"equipmentStatus"=>$request['equipmentStatus'],
"imeiNumber"=>$request['imeiNumber'],
"serialNumber"=>$request['serialNumber'],
"simPhoneNumber"=>$request['simPhoneNumber'],
"smsEmail"=>$request['smsEmail'],
"displayColor"=>$request['displayColor'],
"fuelCapacity"=>$request['fuelCapacity'],
"driverID"=>$request['driverID'],
"lastUpdateTime"=>time()));
$data = array("accountID" => $abc,
"deviceID"=> $request['deviceID'],
"groupID"=>$request['groupID[]'],
"lastUpdateTime"=>time(),
"creationTime"=>time());
$ck = 0;
$ck = DB::table('devicelist')->Insert($data);
$devices = DB::table('device')->simplePaginate(10);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
} catch (ModelNotFoundException $err) {
//Show error page
}
}
}
がどのように私の表それぞれの各値まで複数選択ドロップからのデータを格納する機能を書くことができています行と他の値。誰が私に何をすべきか教えてもらえますか? 「文字列から配列への変換」と「forループ」の挿入方法
複数の項目から配列や文字列をドロップダウンしていますか? @ Rahul Vp –