У меня есть контактная форма во всплывающем окне, но когда я нажимаю кнопку «Отправить», у меня появляется страница, а не перенаправляет меня на домашнюю страницу.
Это мой маршрут
Route::post('/contact_us','HomeController@contact_us')->name('contact_us');
Функция в HomeController.php
public function contact_us(Request $request)
{
$validator=Validator::make($request->all(), [
'name' => 'required',
'phone' => 'required',
'email' => 'required|email'
]);
if($validator->fails())
{
Session::flash('error', "join_us");
return back()->withInput()->withErrors($validator, 'contact');
}
$data = array(
'name' => $request->name,
'email' => $request->email,
'phone' => $request->phone,
'created_at' => date('Y-m-d h:i:s'),
);
$email=$request->email;
DB::table('application_from')->insert($data);
return Redirect::to('/')->with('message', 'Application added successfuly');
}
А открытые и закрываемые теги формы
{{Form::open(array('route'=>'contact_us','method'=>'post'))}}
..... form inputs
{{Form::close()}}
Когда я нажимаю Отправить, я получаю
Not Found
The requested URL /contact_us was not found on this server.
Почему пытается загрузить этот URL, когда он должен перезагрузить домашнюю страницу?
ОБНОВЛЕНИЕ с формой
<div class="modal-body">
{{Form::open(array('route'=>'contact_us','method'=>'post'))}}
<div class="form-group {{ $errors->contact->has('name') ? 'has-error' : '' }}">
@if ($errors->contact->has('name'))
<span class="small text-danger ">
<b>{{ $errors->contact->first('name') }}</b>
</span>
@endif
<input type="text" name="name" class="form-control" placeholder="Name" >
</div>
<div class="form-group {{ $errors->contact->has('email') ? 'has-error' : '' }}">
@if ($errors->contact->has('email'))
<span class="small text-danger ">
<b>{{ $errors->contact->first('email') }}</b>
</span>
@endif
<input type="text" name="email" class="form-control" placeholder="Email" >
</div>
<div class="form-group {{ $errors->contact->has('phone') ? 'has-error' : '' }}">
@if ($errors->contact->has('phone'))
<span class="small text-danger ">
<b>{{ $errors->contact->first('phone') }}</b>
</span>
@endif
<input type="text" name="phone" class="form-control" placeholder="Phone" >
</div>
<div class="form-group text-center">
<button type="submit" class="btn btn-custom btn-sm btn-block">Submit</button>
</div>
{{Form::close()}}
</div>
ОБНОВЛЕНИЕ 2: функция отправки почты
Mail::send('contact_us_email', $data, function($message) use ($email){
$message->to($email)->subject('Site')->cc('info@example.com');
$message->from('info@example.com');
});