There is a helper for booleans
$is_active = $request->boolean('active');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, everyone
I can't figure out how to combine the request form. I have a field active, a checkbox toggle switch. When this is checked, I have active in the request, otherwise it is not.
array:3 [▼
"name" => "Georgia"
"currency_id" => "2"
"active" => "1"
]
array:2 [▼
"name" => "Georgia"
"currency_id" => "2"
]
Active field boolean. Update method in controller. I'm trying to check if a field is actively present set the value to true otherwise not false.
public function update(Country $country, UpdateCountryRequest $request)
{
$is_active = $request->has('active'); // true | false
$request->merge(['active' => $is_active]);
$country->update($request->validated());
return redirect()->route('country.index')->with('status', 'Country updated!');
}
My request form class
public function rules()
{
// $this->merge(['active' => $this->has('active')]);
return [
'name' => 'required|string|max:255|unique:countries,name,'. $this->country->id,
'currency_id' => 'required|numeric|exists:currencies,id',
'active' => 'boolean'
];
}
But when i call $request->validated(), the state is not checked, active is still missing in the request. Can you please tell me how to add an active field to the request and check the validation?
Please or to participate in this conversation.