FareedR
1 month ago
453
3
Laravel

in_array key and list of data

Posted 1 month ago by FareedR

so i got a form that need to tick (checkbox). and the tick(checkbox) is an array . am i missing somewhere ?

$is_contradicts    = $request->has('contradict');
$contradicts = [];

if($is_contradicts){
	$contradicts = $request->get('contradict');
}

foreach ($time_frames as $key => $time_frame){
	$analysis = new Analysis([
		'stock_id'      => $stock->id,
                'time_frame'    => $time_frame,
                'description'   => $descriptions[$key],
                'is_contradict' => in_array($key,$contradicts) ? 1 : 0
	]);
	$analysis->save();
}
//example contradicts
0 => '1'

dd(in_array($key,$contradicts); // false -- supposedly true right ??

//result
// db analyses
stock_id | time_frame | description | is_contradict
1			10			Week		0

// expected result
// db analyses
stock_id | time_frame | description | is_contradict
1			10			Week		1

Please sign in or create an account to participate in this conversation.