it says that my column cannot be null but when I dump my data, it’s not null.
I want to store the the data from the dropdown to the database it says the column is null.
controller:
public function store(Request $request)
{
$household = new HouseholdHead;
$household->name = $request->name;
$household->purok_id = $request->purok;
$household->env_hazard_id = $request->hazards;
$household->number_of_adults = $request->adults;
$household->save();
$categories = ['religion', 'residence', 'type', 'toilet', 'water_source','garbage', 'alcohol','dental', 'h_service', 'm_service', 'routine', 'exposure', 'reasons', 'insurance', 'info', 'w_hazards', 'c_hazards', 'unmet', 'improve', 'screening' ];
foreach ($categories as $category) {
$sdohCategory = new SDOHCategoryHousehold();
$sdohCategory->household_head_id = $household->id;
$sdohCategory->sdoh_category_id = $request->get($category);
$sdohCategory->save();
}
return redirect()->route('admin.household.index')->with('success', 'Household Added Successfully!');
}
dump data:
2
Answers
Your array has "m_service" but your request has "m_service_id=" because of that not found but it try to save and your column not null
If you fill some field of the method and it’s null when inserting into DB, probably you need to add that into YourModel::$fillable array