Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ethar's avatar
Level 5

in_array(): Argument #2 ($haystack) must be of type array,

i have this eloquent code

$payaments=Equipment::where('vehicle_id',$id)->pluck('equipment_value');

when make return $payaments its return the following array

[
"payment_method_types_pay1",
"payment_method_types_pay2",
"payment_method_types_pay3",
"payment_method_types_pay4",
"ext_int_sunroof_norm",
"ext_int_furniture_leat",
]

in blade i want to check if value in_array checkbox must be checked

<input type="checkbox" name="payament_method" @if(in_array('payment_method_types_pay1',$payaments)) checked @endif>

but i got error

in_array(): Argument #2 ($haystack) must be of type array, I

0 likes
3 replies
automica's avatar
what does the rest of the error say?
1 like
tykus's avatar

Use the Collection contains method

@if($payaments->contains('payment_method_types_pay1')) checked @endif
1 like

Please or to participate in this conversation.