vikas hemanth
vikas hemanth

Reputation: 235

How to check whether specific value exists in request in laravel?

I'm stuck in checking whether a specific value exists in the request. I'm doing like this,

foreach ($variant->sale_channels as $v_sale_channel) {
            $v_sale_channel->enabled = ($request->has('sale_channels_enabled.'.$v_sale_channel->sale_channel_id)) ? true : false;
            $variant_sale_channels[] =  $v_sale_channel;
        }

Am I doing it wrong $request->has('sale_channels_enabled.'.$v_sale_channel->sale_channel_id)

sale_channels_enabled is an array which contains only sale channel id's. I want to check weather a specific value exists in that array or not.

Upvotes: 1

Views: 137

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163978

You can use in_array():

if (in_array($v_sale_channel->sale_channel_id, $request->sale_channels_enabled))

Upvotes: 3

Related Questions