联系表单错误MethodNotAllowedHttpException

时间:2017-10-21 19:08:16

标签: laravel contact-form

我正在尝试在Laravel中创建一个联系表单 当我提交消息时,我收到了这个错误 我是laravel的新手,所以我不知道为什么会出现

  

routes.php文件

    Route::post('/contact/sendmail', [
   'uses'   => 'ContactMessageController@postSendMessage',
   'as'     => 'contact.send'
]);
  

ContactMessageController.php

    class ContactMessageController extends Controller
{

    public function postSendMessage(Request $request) 
    {
        $this->validate($request, [
            'email' => 'required|email',
            'name' => 'required|max:100',
            'subject' => 'required|max:140',
            'message' => 'required|min:10'
        ]);
        $message = new ContactMessage();
        $message->email = $request['email'];
        $message->sender = $request['name'];
        $message->subject = $request['subject'];
        $message->body = $request['message'];
        $message->save();
        return redirect()->route('contact')->with(['success' => 'Message Succesfully sent']);
    }
}

  

contact.blade.php

    @extends ('layouts.master')

@section('title')
    Contact
@endsection

@section('styles')
    <link rel="stylesheet" href="{{ URL::secure('src/css/form.css') }}" />
@endsection

@section('content')
    @include('includes.info-box')
    <form action="{{ route('contact.send') }}" mathod="post" id="contact-form">
        <div class="input-group">
            <label for="name">Your Name</label>
            <input type="text" name="name" id="name" value="{{ Request::old('name') }}" />
        </div>
        <div class="input-group">
            <label for="email">Your E-Mail</label>
            <input type="text" name="email" id="email" value="{{ Request::old('email') }}" />
        </div>
        <div class="input-group">
            <label for="subject">Subject</label>
            <input type="text" name="subject" id="subject" value="{{ Request::old('subject') }}" />
        </div>
        <div class="input-group">
            <label for="message">Your Message</label>
            <textarea name="message" id="message" rows="10">{{ Request::old('message') }}</textarea>
        </div>
        <button type="submit" class="btn">Submit Message</button>
        <input type="hidden" value="{{ Session::token() }}" name="_token" />
    </form>
@endsection

我无法找到我收到此错误的原因

MethodNotAllowedHttpException in RouteCollection.php line 218:

1 个答案:

答案 0 :(得分:1)

只是一个错字。您需要将mathod="post"更改为method="post"