Laravel 5.1 : htmlentities() expects parameter 1 to be string, array given - php

I'm encountering an error "htmlentities() expects parameter 1 to be string, array given", when I debug my code, this line from controller throwing the error.
return redirect()->back()->withErrors($validator)->withInput();
Controller
$rules = array(
'email' => 'required|email|unique:inspector_details', // required and must be unique in the ducks table
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$messages = $validator->messages();
return redirect()->back()->withErrors($validator)->withInput();
}
VIEW
{!! Form::open(array('route' => 'inspector.store','class' => 'form','id' => 'createinspector','name' => 'createinspector','files' => true)) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="uid" id="uid" value="" />
<div class="col-md-6">
<div class="form-group">
<label>Name<span class="redmark"> *</span></label>
<input type="text" class="form-control" name="firstname" id="firstname" style="margin-bottom: 3px" value="{{ Input::old('firstname') }}" placeholder="Enter Name" required="required">
</div>
<div class="form-group">
<label>Email<span class="redmark"> *</span></label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="email" class="form-control" name="email" id="email" placeholder="Email" value="{{ Input::old('email') }}" required="required">
</div>
<input type="checkbox" name="emailprivate" value="{{ Input::old('emailprivate') }}" id="emailprivate" style="margin-top: 3%"> <span style="font-weight : 100" >Keep email private.</span>
</div>
<div class="form-group">
<label>Zip Code<span class="redmark" id="zipvalidation" style="font-weight : 100;display: none"> Enter either 5 or 9 digits.</span></label>
<input type="text" class="form-control" name="zip" id="zip" onkeydown="validateNumber(event);" maxlength="9" value="{{ Input::old('zip') }}" placeholder="Enter Zip Code">
</div>
<div class="form-group">
<label>Company<span class="redmark"> *</span></label>
<input type="text" class="form-control" name="company" id="company" value="{{ Input::old('company') }}" placeholder="Enter Company Name">
</div>
<div class="form-group">
<label>Website</label>
<input type="url" class="form-control" name="website" id="website" value="{{ Input::old('website') }}" placeholder="Enter Website url e.g http://www.google.com">
</div>
<div class="form-group">
<label>Phone Number</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="phone" id="phone" onkeydown="validateNumber(event);" value="{{ Input::old('phone') }}" placeholder="Enter Phone number">
</div>
</div>
<div class="form-group">
<label>Free text</label>
<textarea class="form-control" rows="2" name="freetext" id="freetext" value="{{ Input::old('freetext') }}" placeholder="Enter Text"></textarea>
</div>
<div class="form-group">
<label for="exampleInputFile">Select logo</label>
{!! Form::file('logoimage', null) !!}
<p class="help-block"></p>
</div>
<!-- /.form-group -->
</div>
<!-- /.col -->
<div class="col-md-6">
<div class="form-group">
<label>Inspection Type</label>
<select class="form-control select2" name="inspectiontype[]" id="inspectiontype" value="{{ Input::old('inspectiontype') }}" multiple="multiple" data-placeholder="Select Inspection Type" style="width: 100%;">
<option value="home" selected="selected">home</option>
<option value="roof">roof</option>
<option value="asbestos">asbestos</option>
<option value="lead">lead</option>
<option value="HVAC">HVAC</option>
<option value="pest">pest</option>
<option value="septic">septic</option>
<option value="environmental">environmental</option>
<option value="plumbing">plumbing</option>
<option value="zoning">zoning</option>
<option value="mold">mold</option>
<option value="wood destroyin g organisms (WDO)">wood destroying organisms (WDO)</option>
</select>
</div>
<div class="form-group">
<label>Company Begin Date:</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control pull-right" name="companybegindate" id="companybegindate" value="{{ Input::old('companybegindate') }}" id="datepicker">
</div>
<!-- /.input group -->
</div>
<div class="form-group">
<label>street address 1<span class="redmark"> *</span></label>
<input type="text" class="form-control" name="residaddress1" id="residaddress1" value="{{ Input::old('residaddress1') }}" placeholder="Enter Street Address 1">
</div>
<div class="form-group">
<label>street address 2<span class="redmark"> *</span></label>
<input type="text" class="form-control" name="residaddress2" id="residaddress2" value="{{ Input::old('residaddress2') }}" placeholder="Enter Street Address 2">
</div>
<div class="form-group">
<label>City</label>
<input type="text" class="form-control" name="city" id="city" value="{{ Input::old('city') }}" placeholder="Enter City">
</div>
<div class="form-group">
<label>State<span class="redmark" id="statevalidation" style="font-weight : 100;display: none"> Enter two characters only e.g NJ</span></label>
<input type="text" class="form-control" name="state" id="state" value="{{ Input::old('state') }}" placeholder="Enter State e.g NJ">
</div>
<div class="form-group">
<label>Licensing:</label>
<input type="text" class="form-control" name="licname" id="licname" value="{{ Input::old('licname') }}" style="margin-bottom: 2px" placeholder="Enter Licensing name">
<input type="text" class="form-control" name="licid" id="licid" style="margin-bottom: 2px" value="{{ Input::old('licid') }}" placeholder="Enter Licensing ID">
<input type="text" class="form-control" name="licurl" id="licurl" style="margin-bottom: 2px" value="{{ Input::old('licurl') }}" placeholder="Enter URL to governing body">
</div>
<!-- /.form-group -->
</div>
<div class="col-md-12">
<div class="box-footer pull-left">
<button type="submit" class="btn btn-primary" onclick="return validate_data()">Create Inspector</button>
</div>
</div>
{!! Form::close() !!}
Any help is much appreciated..

I suppose it is because you try to set input value as array.
<select class="form-control select2" name="inspectiontype[]" id="inspectiontype" value="{{ Input::old('inspectiontype') }}" multiple="multiple" data-placeholder="Select Inspection Type" style="width: 100%;">
Here you try set array of ids as value of select, but you need to add selected attribute to selected option.
{{ Input::old('inspectiontype') }}
transforms to
<?php echo htmlentities(array('id1', 'id2'), ENT_QUOTES, 'UTF-8', false)?>
I would recommend you to use laravel collective form it will do it for you

Related

Old data not displayed in edit.blade.php

This is my edit method:
public function edit(User $user)
{
// ...
return view('admin.biodata.edit',
[
'title' => 'Edit Biodata',
'active' => 'biodata',
'majors' => Major::all(),
'biodata' => $user
]
);
}
edit.blade.php
#extends('admin.adminDashboard.layouts.main')
#section('container')
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2"></div>
<h1>Edit Student</h1>
<div class="container">
<form action="{{url('admin/biodata')}}" method="POST">
#csrf
<input type="hidden" name="id" value="{{ $biodata->id }}">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" value="{{$biodata->name}}">
</div>
<div class="form-group">
<label for="nrp">NRP</label>
<input type="text" class="form-control" id="nrp" name="nrp" placeholder="Enter NRP" value="{{$biodata->nrp}}">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" value="{{$biodata->email}}">
</div>
<div class="form-group">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" name="address" placeholder="Enter address" value="{{$biodata->address}}">
</div>
<div class="form-group">
<label for="generation">Generation</label>
<input type="text" class="form-control" id="generation" name="generation" placeholder="Enter generation" value="{{$biodata->generation}}">
</div>
<div class="form-group">
<label for="major">Major</label>
<select class="form-control" id="major" name="major_id">
#foreach ($majors as $major)
<option value="{{$major->id}}">{{$major->nama_jurusan}}</option>
#endforeach
</select>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
#endsection
When I press the edit button from the index view, the old data is not displayed in the view admin.biodata.edit. I thought I have already passed the user data through the biodata variable.
Replace the value in the template with
value="{{old('name',$biodata->name)}}"

can't connect a laravel api.php rout from an html form

I am trying to post a form from a HTML file to a live database using laravel api.php route. But it's yielding the following error :
my api.php looks like :
<?PHP
use Illuminate\Http\Request;
use App\Http\Controllers\User\PageController;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('summitRegistration',[PageController::class,'summitRegistration']);
My HTML code :
<form action="https://www.aspireelearning.com/summitRegistration" method="POST">
<div class="col-12 col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="full_name" id="full_name"
placeholder="Your Full Name">
<input type="text" class="form-control" name="phone" id="phone"
placeholder="Phone Number">
<input type="text" class="form-control" name="profession" id="profession"
placeholder="Profession">
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<input type="email" class="form-control" name="email" id="email"
placeholder="Email Address" required>
<input type="text" class="form-control" name="organization" id="organization"
placeholder="Organization/Institute">
<select class="form-control country-search" name="country" id="country">
<option value="">Your Country</option>
<option value="">USA</option>
<option value="">UK</option>
</select>
</div>
</div>
<div class="col-12 text-center">
<button type="submit" class="btn btn-danger">
CONFIRM
</button>
</div>
</form>
i have update action and also added #csrf token now i hope you will get your out put .
<form action="https://www.aspireelearning.com/api/summitRegistration" method="POST">
//#csrf
<div class="col-12 col-md-6">
<div class="form-group">
<input type="text" class="form-control" name="full_name" id="full_name"
placeholder="Your Full Name">
<input type="text" class="form-control" name="phone" id="phone"
placeholder="Phone Number">
<input type="text" class="form-control" name="profession" id="profession"
placeholder="Profession">
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<input type="email" class="form-control" name="email" id="email"
placeholder="Email Address" required>
<input type="text" class="form-control" name="organization" id="organization"
placeholder="Organization/Institute">
<select class="form-control country-search" name="country" id="country">
<option value="">Your Country</option>
<option value="">USA</option>
<option value="">UK</option>
</select>
</div>
</div>
<div class="col-12 text-center">
<button type="submit" class="btn btn-danger">
CONFIRM
</button>
</div>
</form>
You have to add api as prefix https://www.aspireelearning.com/api/summitRegistration

Only created_at and Updated_at column accepting data in my newly Created voyager laravel Database table

i add a new table using the voyager database menu. the problem is that i can't create new data with my newly created database... anytime i try to insert a new data, its only the created_at and Updated_at column that is populated
and the code:
<form clas[s="form-edit-add" role="form"][1]
action="#if(isset($dataTypeContent->id)){{
route('voyager.'.$dataType->slug.'.update', $dataTypeContent->id) }}#else{{
route('voyager.'.$dataType->slug.'.store') }}#endif"
method="POST" enctype="multipart/form-data">
<!-- PUT Method if we are editing -->
#if(isset($dataTypeContent->id))
{{ method_field("PUT") }}
#endif
<!-- CSRF TOKEN -->
{{ csrf_field() }}
<div class="panel-body">
<div class="form-group">
<label for="name">Staff_id</label>
<input type="text" class="form-control"
name="Staff_id"
placeholder="Staff_id" id="Staff_id"
value="#if(isset($dataTypeContent-
>Staff_id)){{ old('Staff_id', $dataTypeContent->Staff_id)
}}#else{{old('Staff_id')}}#endif">
</div>
<div class="form-group">
<label for="name">Title</label>
<input type="text" class="form-control"
name="title"
placeholder="title" id="title"
value="#if(isset($dataTypeContent-
>title)){{ old('title', $dataTypeContent->title)
}}#else{{old('title')}}#endif">
</div>
div class="form-group">
<label for="name">First_Name</label>
<input type="text" class="form-control"
name="first_name"
placeholder="first_name" id="first_name"
value="#if(isset($dataTypeContent-
>first_name)){{ old('first_name', $dataTypeContent->first_name)
}}#else{{old('first_name')}}#endif">
</div>
<div class="form-group">
<label for="name">Middle_Name</label>
<input type="text" class="form-control"
name="middle_name"
placeholder="middle_Name"
id="middle_name"
value="#if(isset($dataTypeContent-
>middle_name)){{ old('middle_name', $dataTypeContent->middle_name)
}}#else{{old('middle_name')}}#endif">
</div>
<div class="form-group">
<label for="name">Last_Name</label>
<input type="text" class="form-control"
name="last_name"
placeholder="Last_Name" id="last_name"
value="#if(isset($dataTypeContent-
>last_name)){{ old('last_name', $dataTypeContent->last_name)
}}#else{{old('last_name')}}#endif">
</div>
<div class="form-group">
<label for="name">Gender</label>
<input type="text" class="form-control"
name="gender"
placeholder="gender" id="gender"
value="#if(isset($dataTypeContent-
>gender)){{ old('gender', $dataTypeContent->gender)
}}#else{{old('gender')}}#endif">
</div>
<div class="form-group">
<label for="name">DOB</label>
<input type="text" class="form-control"
name="dob"
placeholder="dob" id="dob"
value="#if(isset($dataTypeContent->dob))
{{ old('dob', $dataTypeContent->dob) }}#else{{old('dob')}}#endif">
</div>
<div class="form-group">
<label for="name">Phone_Number</label>
<input type="text" class="form-control"
name="phone_number"
placeholder="phone_number"
id="phone_number"
value="#if(isset($dataTypeContent-
>phone_number)){{ old('phone_number', $dataTypeContent->phone_number)
}}#else{{old('phone_number')}}#endif">
</div>
<div class="form-group">
<label for="name">Unit</label>
<input type="text" class="form-control"
name="unit"
placeholder="unit" id="unit"
value="#if(isset($dataTypeContent->unit))
{{ old('unit', $dataTypeContent->unit)
}}#else{{old('unit')}}#endif">
</div>
<div class="form-group">
<label for="name">Department</label>
<input type="text" class="form-control"
name="department"
placeholder="department" id="department"
value="#if(isset($dataTypeContent-
>department)){{ old('department', $dataTypeContent->department)
}}#else{{old('department')}}#endif">
</div>
<div class="form-group">
<label for="name">Company</label>
<input type="text" class="form-control"
name="company"
placeholder="company" id="company"
value="#if(isset($dataTypeContent-
>company)){{ old('company', $dataTypeContent->company)
}}#else{{old('company')}}#endif">
</div>
<div class="form-group">
<label for="name">Employment_status</label>
<input type="text" class="form-control"
name="employment_status"
placeholder="employment_status"
id="employment_status"
value="#if(isset($dataTypeContent-
>employment_status)){{ old('employment_status', $dataTypeContent-
>employment_status) }}#else{{old('employment_status')}}#endif">
</div>
<div class="form-group">
<label for="name">Guarantor1</label>
<input type="text" class="form-control"
name="guarantor1"
placeholder="guarantor1" id="guarantor1"
value="#if(isset($dataTypeContent-
>guarantor1)){{ old('guarantor1', $dataTypeContent->guarantor1)
}}#else{{old('guarantor1')}}#endif">
</div>
<div class="form-group">
<label for="name">Guarantor2</label>
<input type="text" class="form-control"
name="guarantor2"
placeholder="guarantor2" id="guarantor2"
value="#if(isset($dataTypeContent-
>guarantor2)){{ old('guarantor2', $dataTypeContent->guarantor2)
}}#else{{old('guarantor2')}}#endif">
</div>
<div class="form-group">
<label for="name">Academic_record</label>
<input type="text" class="form-control"
name="academic_record"
placeholder="academic_record"
id="academic_record"
value="#if(isset($dataTypeContent-
>academic_record)){{ old('academic_record', $dataTypeContent-
>academic_record) }}#else{{old('academic_record')}}#endif">
</div>
<div class="form-group">
<label for="name">Work Experience</label>
<input type="text" class="form-control"
name="work_experience"
placeholder="work_experience"
id="work_experience"
value="#if(isset($dataTypeContent-
>work_experience)){{ old('work_experience', $dataTypeContent-
>work_experience) }}#else{{old('work_experience')}}#endif">
</div>
<div class="form-group">
<label for="name">Note</label>
<input type="text" class="form-control"
name="notes"
placeholder="notes" id="notes"
value="#if(isset($dataTypeContent-
>notes)){{ old('notes', $dataTypeContent->notes)
}}#else{{old('notes')}}#endif">
</div>
</div><!-- panel-body -->
<div class="panel-footer">
<button type="submit" class="btn btn-
primary">Submit</button>
</div>
</form>
<iframe id="form_target" name="form_target"
style="display:none"></iframe>
<form id="my_form" action="{{ route('voyager.upload') }}"
target="form_target" method="post"
enctype="multipart/form-data"
style="width:0;height:0;overflow:hidden">
{{ csrf_field() }}
<input name="image" id="upload_file" type="file"
onchange="$('#my_form').submit();this.value='';">
<input type="hidden" name="type_slug" id="type_slug"
value="{{ $dataType->slug }}">
</form>
this is my Model code for the Profiles table:
<?php
namespace TCG\Voyager\Models;
use Illuminate\Database\Eloquent\Model;
use TCG\Voyager\Facades\Voyager;
class Profile extends Model
{
protected $table = 'profiles';
protected $fillable = [
'Staff_id',
'Title',
'First_name',
'Middle_name',
'last_name',
'Gender',
'DOB',
'Phone_number',
'Company',
'Department',
'Unit',
'Date_employed',
'Date_of_exit',
'Mode_of_exit',
'Employment_Status',
'Guarantor1_Details',
'Guarantor2_Details',
'Academic_Record',
'Work_Experience',
'Notes',
];
}
Add this line to the model to allow the remaining data to enter the database
protected $fillable = ['name_of_column', 'name_of_thenextcolumn'];

how to insert multi select drop down data into the database in laravel 5.2

In my form i created multiselect drop down list. i need to store the data which i selected from my multi select drop down to database, table name devicelist along with some value that is taken from my form.
my view page is
#extends('app')
#section('content')
<br><br><br><br><br>
<div class="templatemo-content-wrapper">
<div class="container">
<ol class="breadcrumb">
<li><font color="green">Home</font></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 >--}}
{{--#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>--}}
<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
and my controller page is
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
}
}
}
how can i write the function to store the data from multiselect drop down to my table each value in each row along with other value. Can anyone tell me what should i do? and how to write "string to array" conversion and "for loop" for the insertion
If you are getting array from multi select and want to insert it in one row. You should implode array into comma separated string then insert it in table
Implode function
$val = implode(",",$request['groupID[]']);
Then put $val into your $data array like
$data = array("accountID" => $abc,
"deviceID"=> $request['deviceID'],
"groupID"=>$val,
"lastUpdateTime"=>time(),
"creationTime"=>time());
If you are getting string then explode it
Explode function
$val = explode(",",$request['groupID[]']);
$count = count($val);
for($a=0; $a<$count; $a++){
$data = array("accountID" => $abc,
"deviceID"=> $request['deviceID'],
"groupID"=>$val[$a],
"lastUpdateTime"=>time(),
"creationTime"=>time());
}

how to pass two array variable to view page and the value from there in laravel 5.2

i am creating edit page. So in the form fields i want fetch data ffrom two tables.. so in controller am fetching data from each table to different array variable. and trying to pass those variable to the same view page.. and there tryingf to get one table data for fields and other to make dropdown list. but its showing error
Undefined property: Illuminate\Database\Eloquent\Collection::$groupID
(View: C:\xampp\htdocs\opennGTS\resources\views\vehicle\add.blade.php)
my controller page is giving below
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)->with('grouplist',$grouplist);
} catch (ModelNotFoundException $err) {
//redirect to your error page
}
}
and view page is
#extends('app')
#section('content')
<br><br><br><br><br>
<div class="templatemo-content-wrapper">
<div class="container">
<ol class="breadcrumb">
<li><font color="green">Home</font></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="row">
<div class="col-md-3 margin-bottom-15">
<label class="control-label">Group Membership</label>
<select class="form-control" value="{{ old('groupID') }}" name="groupID" >
#foreach( $grouplist as $group)
#if ($grouplist->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>
any one please tell me how to do this and what wrong i had done in my code. Responses are appreciable.
Inside this foreach
#foreach( $grouplist as $group)
you are doing $grouplist->groupID
instead of $group->groupID
The exception you get is telling that groupID does not exist in the Collection class. In your loop, $grouplist is your Collection and $group is your item
I prefer this way:
return view('vehicle.add',[
'devices'=>$devices,
'groupList'=>$groupList
]);
But, you can use this:
return view('vehicle.add')->with(['devices'=>$devices,'groupList'=>$groupList]);

Categories