Laravel- store json type null data as [null]

Viewed 27

I am trying to store json type data in my database.

migration:

$table->json('email_signature')->nullable();

Model:

protected $casts = [
    'email_signature' => 'array'
];

Controller:

$system->email_signature = $request->input('email_signature');

Data is storing correctly, but when $request is empty, in database it is stored as [null]. If is was NULL then I could make a query using whereNotNull to find if it is null or not. Can it be stored as NULL? Or, how can I catch that [null] value in a query to find if it is null or not?

1 Answers

The quickest solution would be to use json_decode(email_signature) and then check if it is null.

Related