Before you devote my question Please here me out I know this question is asked before but still.
I Have a table inside my database called:delivery_fees
my table
it has 3 columns destination
,domicile
and stopdesk
destination
is the destinationdomicile
is the shipping amount for home deliverystopdesk
is the shipping amount for the post office
I have a query that retrieve all destinations:
$destination = DB::table('delivery_fees')->select('destination')->pluck('destination');
I display it on a select option dropdown menu on my view like this:
<select id="wilaya" wire:model="wil" class="hidden block w-full dropdown-toggle flex items-center justify-between rounded-lg border border-jacarta-100
bg-white py-3 px-3 dark:border-jacarta-600 dark:bg-jacarta-700 dark:text-jacarta-300" onchange="closeFunction()">
@foreach ($destination as $items)
<option value="{{ $items }}">{{ $items }}</option>
@endforeach
</select>
my goal here is when user choses a destination
from the option menu I want to retrieve the related value of domicile
and stopdesk
I tried query builder inside my component like this:
$fees = DB::table('delivery_fees')->select('stopdesk', 'domicile')->where('destination','like',$destination)->get();
it throws Back and error of:SQLSTATE[HY093]: Invalid parameter number
Side Note
when I dd($destination)
I get a collection of an array for all table value
Please Help
Thanks.
2
Answers
looks like you trying t fetch the shipping fees based on the Selected destination from the dropdown menuu.
you Should try this:
The error "SQLSTATE[HY093]: Invalid parameter number" occurs because you’re using the
whereLike
method with the$destination
variable, which is a collection of destinations, not a single destination value. ThewhereLike
method expects a single value to compare against.To fix this issue, you can modify your query to use the
whereIn
method, which is specifically designed to compare against a collection of values. Here’s the updated query:This query will select the
stopdesk
anddomicile
columns for all destinations that match the values in the$destination
collection.