Laravel - 无法访问错误包

时间:2016-05-21 07:26:52

标签: laravel laravel-5.2

我无法看到任何验证错误,$errors始终为空,我无法理解原因。 我做了这么多次,但在这个项目中,我没有看到问题。

这里的表格是:

@if( count( $errors ) > 0 )
        <div class="alert alert-danger">
            <ul>
                @foreach( $errors->all() as $error )
                <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
    {{ Form::open(['url'=>route('admin.roles.store'), 'method'=>'post']) }}
        <input type="text" name="name">
        {{ Form::submit() }}
    {{ Form::close() }}

这是我的Controller方法:

public function store(CreateRoleRequest $request)
{
    $this->validate($request, [
        'name' => 'required'
    ]);
}

路由使用中间件组:

'backend' => [
            'auth',
            \App\Http\Middleware\Boilerplate\CheckIfUserCanAccessToBackend::class
        ]

这是中间件:

<?php

namespace App\Http\Middleware\Boilerplate;

use Closure;

class CheckIfUserCanAccessToBackend
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = $request->user();

        // Admin can access
        if( $user->hasRole('admin') )
        {
            return $next($request);
        }

        // The user has the permission?
        if($user->can('access_backend') ){

            return $next($request);
        }

        // Can't access
        return abort(403);
    }
}

我不知道最近有什么想法?

1 个答案:

答案 0 :(得分:1)

可能导致此问题的一件事是手动将DateTime dt = DateTime.ParseExact(callobj.CallStartTime, "yyyy-MM-dd hh:mm tt", CultureInfo.GetCultureInfo("en-US")); // String CallStartTimeString = Convert.ToDateTime(callobj.CallStartTime); var s = dt.ToString("d-M-yyyy hh:mm tt", CultureInfo.InvariantCulture); DateTime datetimes = DateTime.ParseExact(s, "d-M-yyyy h:mm tt", CultureInfo.InvariantCulture); 中间件添加到web路由in Laravel 5.2.27 or higher