Answer the question
In order to leave comments, you need to log in
How to change route on wrong laravel validation in request?
There is a request in which the form is validated, how can I route with an anchor if an error occurs?
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CallbackRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'telephone' => 'required|max:12',
'name' => 'required|max:20'
];
}
public function messages()
{
return [
'telephone.required' => 'Поле Телефон - обязательно.',
'name.required' => 'Поле Имя - обязательно.',
'telephone.max' => 'Телефон введен не верно.',
'name.max' => 'Введите короткую форму имени.'
];
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\CallbackRequest;
use App\Models\Callback;
class CallbackController extends Controller
{
public function submit(CallbackRequest $callback_request)
{
$callback = new Callback();
$callback->name=$callback_request->input('name');
$callback->telephone=$callback_request->input('telephone');
$callback->save();
return redirect()->route('welcome', '#callback');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question