try changing the name of your select element to name="accessory_id[]" adding the brackets at the end, which will tell PHP it's an array.
Then just know that $request->accessory_id will be an array in your controller.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys, I need a small help. I have a booking form where I can choose more than one accessory. My input is defined in this way:
<div class="col-md-12">
<div class="form-group">
<label class="control-label" for="accessories">Choose your Accessories</label>
<select name="accessory_id" class="form-control" multiple="multiple">
@foreach($accessories as $accessory)
<option value="{{$accessory->id}}">{{$accessory->name}}</option>
@endforeach
</select>
</div>
</div>
when I select more than one accessory I have an "Array to string conversion" error.
By the way the relationships are defined in this way:
Booking.php
public function accessories()
{
return $this->hasMany(Accessory::class);
}
Accessory.php
public function bookings()
{
return $this->belongsToMany(Booking::class);
}
meaning that a booking can have more than one accessory and an accessory can belong to many bookings.
Any ideas? Thanks
Please or to participate in this conversation.