dongtan7418 2016-07-27 12:26
浏览 94
已采纳

Laravel验证错误显示

I am trying to get validation errors to display in my application and have run into a wall.

I have tried this a few different ways, this is how I have it setup currently...

My routes look like this:

<?php

Route::group(['middleware' => ['web']], function () {

    Route::get('/', [
        'as'   => 'home',
        'uses' => 'HomeController@index'
    ]);

    Route::post('/mailing', [
        'as' => 'mailing.create',
        'uses' => 'MailingController@create'
    ]);

});

My mailing controller looks like this:

class MailingController extends Controller
{
    public function create(Request $request)
    {
        $this->validate($request, [
            'email' => 'required',
        ]);
        dd($request->email);
    }
}

My form looks like this...

            <form action="{{ route('mailing.create') }}" method="post">

                <label for="email">
                    Email
                    <input type="text" name="email" id="email">
                    @if ($errors->has('email'))
                        {{ $errors->first('email') }}
                    @endif
                </label>

                <input type="submit">
                {{ csrf_field() }}
            </form>

When I submit an empty form it goes to the create method in the MailingController however nothing happens, no errors are displayed. Just the form.

Really this should work, could the issue possibly be that the example above was good for Laravel 5.1 but does not work in the latest 5.2 version?

Many thanks in advance for your kind consideration.

  • 写回答

2条回答 默认 最新

  • dqvy87517 2016-07-27 13:07
    关注

    You can see in the official documentation that the web middleware group is applied by default:

    Keep in mind, the web middleware group is automatically applied to your default routes.php file by the RouteServiceProvider.

    If you execute

     php artisan route:list
    

    You can see that the middleware is applied two times to the web router.

    You have to delete the group

    Route::group(['middleware' => ['web']], function () {
    
    }
    

    This have changed in a minor 5.2 version, so it is probable that you have this error after a "composer update".

    More info here and here.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?