单页网站上的Laravel联系表格 [英] Laravel Contact form on Single Page website

查看:59
本文介绍了单页网站上的Laravel联系表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为单页网站上的Laravel联系人表单获取正确的路由,但是我不确定到目前为止如何应用这些路由,因为我已经对非单页网站进行了处理(视差-如网站/可滚动浏览).

I'm trying to get the correct routes for the Laravel Contact form on a single page website but I'm not sure how to apply the routes so far, since i've done it with sites that aren't single page (parallax - like website/ scrollable).

这些是我正在创建的路线,因此所有内容都保留在主页上(根本没有重定向,因为它是一个可滚动的页面网站)

These are the routes I am creating, so everything stays on the homepage(no redirects at all because it's a one page scrollable website)

 Route::get('/', 'ContactUsController@create')->name('contact.create');
 Route::post('/', 'ContactUsController@store')->name('contact.store');

我的控制器"如下所示:请注意,创建控制器将视图返回到我的索引,该视图当然是这样路由的('/'),

My Controller looks like this: Please note that the create controller returns the view to my index which of course is routed like so ('/'),

    namespace App\Http\Controllers;

        use Illuminate\Http\Request;
        use App\Http\Requests;
        use App\Mail\ContactEmail;

        class ContactUsController extends Controller
        {
            public function create()
            {

                return view('index');
            }

            public function store(Request $request)
            {
                $contact = [];

                $contact['name'] = $request -> get('name');

                $contact['phone'] = $request -> get('phone');
                $contact['email'] = $request -> get('email');

                $contact['subject'] = $request -> get('subject');
                $contact['message'] = $request -> get('message');

                //send mail logic here

Mail::to(config('mail.support.address'))->send(new ContactEmail($contact));

                flash('Your Message has been sent!) -> success();
                return redirect()-> route('/');
            }
        }

以下是我的联系表格:

{!! Form::open(['route' => 'contact.store', 'class' => 'text-light '])!!}

  {!! Form::label('name', 'Your Name', ['class' => 'text-light'])!!}
  {!! Form::text('name', null, ['class' => 'form-control text-light'])!!}


  {!! Form::label('phone', 'tel', ['class' => 'text-light'])!!}
 {!! Form::text('phone', null, ['class' => 'form-control text-light'])!!}


 {!! Form::label('email', 'Email', ['class' => 'text-light'])!!}
 {!! Form::text('email', null, ['class' => 'form-control text-light'])!!}

 {!! Form::label('subject', 'Subject', ['class' => 'text-light'])!!}
 {!! Form::text('subject', null, ['class' => 'form-control text-light'])!!}

 {!! Form::label('message', 'Your Message Here..', ['class' => 'text-light'] )!!}
 {!! Form::textarea('message', null, ['class' => 'form-control text-light'])!!}

 {!! Form::submit('Submit', ['class' => 'btn btn-info']) !!}

      {!! Form::close() !!}

              @if($errors -> any())
                 <div class="alert alert-danger">
                        <ul>
                     @foreach($errors -> all() as $error)
                             <li>{{ $error }}</li>
                                  @endforeach
                        </ul>
                  </div>
              @endif
              @include('flash::message')

解决了问题:

//routes for contact form
Route::get('/contacts', 'ContactUsController@create')->name('contact.create');
Route::post('/contacts', 'ContactUsController@store')->name('contact.store');

其他都一样.谢谢大家的支持.

Everything else same. Thanks guys for all support.

推荐答案

///在web.php中创建路由

//Create the routes in web.php

Route::get('contact',['as' => 'contact, 'uses' => 'ContactController@create']);
Route::post('contact',['as' => 'contact', 'uses' => 'ContactController@store']);

这篇关于单页网站上的Laravel联系表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆