Laravel 5 - 请求验证不返回消息

时间:2017-08-18 19:17:13

标签: php laravel validation

我试图从简单的联系表单发布,我还为它创建了一个简单的验证规则:

<?php

namespace App\Http\Requests\Contact;

use Illuminate\Foundation\Http\FormRequest;

class ContactCreateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return false;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email' => 'required|email',
            'message' => 'max:500',
        ];
    }
}

这是我发布的表格:

@extends('public.layouts.master')
@section('content')
<div class="container contact-form">
    <div class="row">
      <div class="col-md-6 col-md-offset-3">
        @if (session('status'))
            <div class="alert alert-warning alert-dismissible" role="alert">
              <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              {{ session('status') }}
            </div>
        @endif
        <div class="well well-sm">
          <form autocomplete="off" class="form" method="POST" action="{{ url('/contact') }}">
          {{ csrf_field() }}
          <fieldset>
            <legend class="text-center">Contact us</legend>

            <!-- Name input-->
            <div class="form-group">
              <label class="col-md-3 control-label" for="name">Name</label>
              <div class="col-md-9">
                <input id="name" name="name" type="text" placeholder="Your name" class="form-control">
              </div>
            </div>

            <!-- Email input-->
            <div class="form-group">
              <label class="col-md-3 control-label" for="email">Your E-mail</label>
              <div class="col-md-9">
                <input id="email" name="email" type="email" placeholder="Your email" class="form-control" required>
                @if ($errors->has('email'))
                    <span class="help-block">
                        <strong>{{ $errors->first('email') }}</strong>
                    </span>
                @endif
              </div>
            </div>

            <!-- Message body -->
            <div class="form-group">
              <label class="col-md-3 control-label" for="message">Your message</label>
              <div class="col-md-9">
                <textarea class="form-control" id="message" name="message" placeholder="Please enter your message here..." rows="5"></textarea>
                @if ($errors->has('message'))
                    <span class="help-block">
                        <strong>{{ $errors->first('message') }}</strong>
                    </span>
                @endif
              </div>
            </div>

            <!-- Form actions -->
            <div class="form-group">
              <div class="col-md-12 text-right">
                <button type="submit" class="btn btn-primary">Submit</button>
              </div>
            </div>
          </fieldset>
          </form>
        </div>
      </div>
    </div>
</div>
@endsection

这是我发布的控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Requests\Contact\ContactCreateRequest;
use App\Events\MessageSent;

class ContactController extends Controller
{
    /**
     * Show the first page.
     *
     * @return \Illuminate\Http\Response
     */
    public function show()
    {
        return view('contact.contact-form');
    }

    public function create(ContactCreateRequest $request)
    {
        event(new MessageSent($request->message, $request->email));

        return redirect()->back()->with('status', 'The message was succesfully sent to us, we will get back to you inside of 24 hours');
    }
}

但是,当我试图发布任何内容时,我只会收到错误:

  

禁止

为什么会这样,如果验证没有通过,为什么我在联系表单中看不到任何错误消息?

1 个答案:

答案 0 :(得分:1)

如果您尚未登录,则应尝试在申请文件中更改此内容

SELECT SubStr(CAB_MOMENTO,1,10) ||' '||
   CASE WHEN To_Number(SubStr(cab_momento,11,2)) < 15 THEN '00-15'
        WHEN To_Number(SubStr(cab_momento,11,2)) < 30 THEN '15-30'
        WHEN To_Number(SubStr(cab_momento,11,2)) < 45 THEN '30-45'
        ELSE '45-00'
   END As time_period, Sum(sul_oeste_auto), 
Sum(sul_oeste_com),Sum(norte_leste_auto), Sum(norte_leste_com)
FROM (

SELECT SUBSTR(CAB_MOMENTO,1,12) AS cab_momento,
Sum(CASE WHEN COMVSAUTO = '1' AND NOME IN ('SUL','OESTE') THEN 1 ELSE 0 END) 
SUL_OESTE_AUTO,
Sum(CASE WHEN COMVSAUTO = '0' AND NOME IN ('SUL','OESTE') THEN 1 ELSE 0 END) 
SUL_OESTE_COM,
Sum(CASE WHEN COMVSAUTO = '1' AND NOME IN ('NORTE','LESTE') THEN 1 ELSE 0 
END) NORTE_LESTE_AUTO,
Sum(CASE WHEN COMVSAUTO = '0' AND NOME IN ('NORTE','LESTE') THEN 1 ELSE 0 
END) NORTE_LESTE_COM FROM
(SELECT a.idtransaccion, a.cab_momento, a.cab_via, a.comvsauto, b.NOME
FROM
(select idtransaccion, cab_momento, cab_via, cab_estacion AS ESTACION,
CASE ctl_clase
WHEN '01' THEN 1
WHEN '07' THEN 1
WHEN '08' THEN 1
ELSE 0
END comvsauto
FROM usrhost.atransaccion
WHERE cab_momento > '20170818000000') a
INNER join
(SELECT sen.estacion AS ESTACION, via.via AS VIA, sen.nome AS NOME FROM 
usrhost.aestacion_sentido sen
INNER JOIN usrhost.avia via ON
sen.estacion = via.estacion
AND SubStr(via.via,3,1) = sen.sentido
ORDER BY 1,2) b ON
b.VIA = a.cab_via
AND b.ESTACION = a.ESTACION)
GROUP BY SUBSTR(CAB_MOMENTO,1,12)
ORDER BY 1)
GROUP  BY SubStr(CAB_MOMENTO,1,10),CASE WHEN 
To_Number(SubStr(cab_momento,11,2)) < 15 THEN '00-15'
        WHEN To_Number(SubStr(cab_momento,11,2)) < 30 THEN '15-30'
        WHEN To_Number(SubStr(cab_momento,11,2)) < 45 THEN '30-45'
        ELSE '45-00'
   END