mleontenko
5 months ago
373
5
Laravel

Storing array of integers to database field

Posted 5 months ago by mleontenko

I have the following table:

record:
	id: 1
	version: "1.0"
	options: [1, 3, 5]

The controller should look like this:

public function store(Request $request)
{
	$record = new Record;
	$record->version = "1.0";
	$record->options = $request->options;

	return redirect()->to('/records')->with('success', 'Record saved.');
}

Options field in database should contain an array of integers, but I'm unsure which data type to use in migration. Any suggestions?

Also, will I be able to query this field? E. g. all records that contain option 1.

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