简单的联系表单没有显示验证错误或发送消息


Simple contact form not showing validation errors or sending the message

我在Laravel 5中有一个简单的联系人表单。如果我用空字段提交,页面会重新加载,但不会显示验证的错误消息。如果我填写表单并提交,就会得到以下错误:

FileViewFinder.php第140行InvalidArgumentException: View [email .php][消息]未找到。

那是因为我没有这样的观点,我不知道该放什么进去,Laravel的文档对这个主题也不清楚:

传递给send方法的第一个参数是应该用作电子邮件正文的视图的名称。

不知道那是什么意思

路线

Route::get('contact','HomeController@contactus');
Route::post('contact_request', 'HomeController@contactRequest');

HomeController

public function contactus()
    {
        if (Auth::check()) {
            $count = Cart::count();
        } else {
            $count = 0;
        }
        $contact = Contact::all();
        return view('contact')->with('contact', $contact)->with('count', $count);
    }
public function contactRequest() {
        if (Auth::check()) {
            $count = Cart::count();
        } else {
            $count = 0;
        }
        $contact = Contact::all();
        //Get all the data and store it inside Store Variable
        $data = Input::all();
        //Validation rules
        $rules = array (
            'name' => 'required', 
            'email' => 'required|email',  
            'message' => 'required|min:5'
        );
        //Validate data
        $validator = Validator::make ($data, $rules);
        //If everything is correct than run passes.
        if ($validator -> passes()){
            Mail::send('emails.message', $data, function($message) use ($data)
            {
                //$message->from($data['email'] , $data['first_name']); uncomment if using first name and email fields
                $message->from('feedback@gmail.com', 'feedback contact form');
                //email 'To' field: cahnge this to emails that you want to be notified.
                $message->to('feedback@gmail.com', 'John')->cc('feedback@gmail.com')->subject('feedback form submit');
            });
            // Redirect to page
            return view('contact')
                ->with('message', 'Your message has been sent. Thank You!');

            //return View::make('contact');
        }else{
            //return contact form with errors
            return view('contact')
                ->with('error', 'Feedback must contain more than 5 characters. Try Again.')
                ->with('contact', $contact)
                ->with('count', $count);
        }
    }
视图

<h1 class='siteh1'>Contact Us</h1> 
<hr class='sitehr'/>
<div class="col-md-6 siteleft">
<h2 class='siteh2'>Contact Info</h2>
<div class='contaddr'><label>Address:</label> {!!$contact[0]['Address']!!}</div>
<div class='contphone'><label>Phone:</label> {!!$contact[0]['Phone1']!!} | {!!$contact[0]['Phone2']!!}</div>
<div class='contemail'><label>E-mail:</label> {!!$contact[0]['Email']!!}</div>
<div class='contfollow'><label>Follow us:</label><p>
                            <a href="{!!$contact[0]['Facebook']!!}"><img src="images/fb.png" alt="Facebook"></a>
                            &nbsp;<a href="{!!$contact[0]['Youtube']!!}"><img src="images/youtube.png" alt="Youtube"></a>
                            &nbsp;<a href="{!!$contact[0]['Skype']!!}"><img src="images/skype.png" alt="Skype"></a>
                            &nbsp;<a href="{!!$contact[0]['Google']!!}"><img src="images/gplus.png" alt="Google Plus"></a>
                        </p></div>
</div>
<div class="col-md-4 col-md-offset-2 col-sm-12 col-xs-12">
<p class='siteright'>
Get in touch with us
</p>
    <div class='contform'>
        {!! Form::open(['action' => 'HomeController@contactRequest', 'METHOD' => 'PUT']) !!}
        <ul class="errors">
            @foreach($errors->all('<li>:message</li>') as $message)
            @endforeach
        </ul>
        <div class="form-group">
            {!! Form:: text('name', '', array('placeholder' => 'Your Name', 'class' => 'form-control', 'id' => 'contname', 'rows' => '4' ))  !!}
        </div>
        <div class="form-group">
            {!! Form:: text('email', '', array('placeholder' => 'Your Email', 'class' => 'form-control', 'id' => 'contemail', 'rows' => '4' )) !!}
        </div>
        <div class="form-group">
            {!! Form:: text('phone', '', array('placeholder' => 'Your Phone', 'class' => 'form-control', 'id' => 'contphone', 'rows' => '4' )) !!}
        </div>
        <div class="form-group">
            {!! Form:: textarea('message', '', array('placeholder' => 'Message', 'class' => 'form-control', 'id' => 'contmessage', 'rows' => '4' )) !!}
        </div>

    </div>
    <div class="modal-footer">
        {!! Form::submit('Submit', array('class' => 'btn btn-primary')) !!}
        {!! Form:: close() !!}
    </div>
</div>

电子邮件只是刀片模板,点表示目录结构。刀片模板存储在resources/views中,所以在这种情况下,emails.message将导致Laravel在resources/views/emails中查找文件message.blade.php

用您的消息内容创建文件resources/views/emails/message.blade.php

表单中的所有数据都被传递(通过$data参数),因此您应该能够像这样在消息视图文件中访问它。

Hello {{ $name }}, your phone number is {{ $phone }}
对于主视图模板,你的错误处理代码应该是:
@foreach($errors->all() as $message)
    <li>{{ $message }}</li>
@endforeach`