The recommended place to alter form input before storing it in the database is in the controller's store method. You can use Laravel's built-in validation and then modify the input before saving it to the database. Here's an example:
public function store(Request $request)
{
$validatedData = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:8|confirmed',
]);
// Modify the input before saving it to the database
$validatedData['name'] = strtolower($validatedData['name']);
$user = User::create($validatedData);
return redirect('/home');
}
In this example, we're using Laravel's validation to validate the input. After validation, we're modifying the name input to lowercase before saving it to the database.