vandan's avatar
Level 13

how to enum datatype using multiple values store?

hii i have column like datatype is enum and also store multiple value like comma seperated so is it possible to store ?

here is my code i try but i cant find any solution

here is my migrations

public function up()
	{
    	Schema::table('fraud_alerts', function (Blueprint $table) {
        		$table->enum('alert_for',['disposition','fraudalert'])->after('type')->nullable()->comment('Alert For');
    });
	}

here is my controller code

 public function store(Request $request){
	$requestData = $request->all();
	foreach($requestData['email'] as $i => $list){
		$data = array();
		$all = ['fraudalert','disposition'];
		$rowdata = array();
		if(in_array("all",$requestData['email_alert_for'])){
                    	$rowdata['alert_for'] = implode(',' , $all);
                	 }else{
               		$rowdata['alert_for'] = $requestData['email_alert_for'];
                	 }
		array_push($data,$rowdata);
                	FraudAlert::insert($data);
	}
}

i try but everytime store null value in alert_for column

0 likes
3 replies
Sinnbeck's avatar

Can you please use dd to show us what $data hold just before inserting?

array_push($data,$rowdata);
dd($data);
FraudAlert::insert($data);
1 like
vandan's avatar
Level 13

@sinnbeck

^ array:1 [▼
	0 => array:12 [▼
	"email" => "[email protected]"
		"phone" => null
		"alert_level" => "client"
		"client_id" => "102"
		"salescenter_id" => null
 	"location_id" => null
		"alert_for" => "fraudalert,disposition"
		"added_by" => 348
		"added_for_client" => "102"
		"type" => "email"
		"created_at" => "2020-10-27 09:57:15"
	"updated_at" => "2020-10-27 09:57:15"
	]
]
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Ah now I get your question. The answer is no. You cannot store more that one value in an ENUM column. Either save in a json column, or add another table for this data :)

1 like

Please or to participate in this conversation.