Answer the question
In order to leave comments, you need to log in
How to make changes to Request after validation?
Hello!
Knowledgeable and understanding people, help me, please, to understand.
Here is the registration processing code:
public function store(Request $request)
{
$rules = [
// Всякие правила.
];
$validator = Validator::make($request->except(['_token']), $rules);
if ($validator->fails()) {
return redirect('registration')->withErrors($validator)->withInput();
}
/* Вот это мне нужно внести в Request */
$birthday = $request->input('birthday');
$birthday = implode('.', $birthday);
/* ---------------------------------- */
User::create($request->except(['_token']));
return redirect('registration/success');
}
<div class="form-group">
<label for="password" class="col-sm-5 control-label">Пароль:</label>
<div class="col-sm-7">
<input id="password" name="password" type="password" class="form-control">
</div>
</div>
<div class="form-group">
<label for="password_repeat" class="col-sm-5 control-label">Подтверждение пароля:</label>
<div class="col-sm-7">
<input id="password_repeat" name="password_repeat" type="password" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-5 control-label">Дата рождения:</label>
<div class="col-sm-7">
<div class="row">
<div class="col-sm-3">
<input name="birthday[]" type="text" class="form-control" placeholder="Day">
</div>
<div class="col-sm-4">
<input name="birthday[]" type="text" class="form-control" placeholder="Month">
</div>
<div class="col-sm-5">
<input name="birthday[]" type="text" class="form-control" placeholder="Year">
</div>
</div>
</div>
</div>
Answer the question
In order to leave comments, you need to log in
1) You can get $request->all() and write a new birthday into the resulting array, and then validate it. But it's better to write your own custom validator here so that it validates the original birthday.
2) Because this data is not displayed anywhere. You need to add value="{{ old('password') }}" in the fields:
3) There is a rule "confirmed", which just checks the confirmation of the field:
$rules = [
'password' => 'required|confirmed'
];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question