Reputation: 7618
I can't see any validation error, the $errors
is always empty and I can't figured out why.
I have do this million times but in this project I do not see the problem.
Here the form:
@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() }}
Here my Controller method:
public function store(CreateRoleRequest $request)
{
$this->validate($request, [
'name' => 'required'
]);
}
The route use a middleware group:
'backend' => [
'auth',
\App\Http\Middleware\Boilerplate\CheckIfUserCanAccessToBackend::class
]
And this is the middleware:
<?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);
}
}
I have no idea about whats going on, any idea?
Upvotes: 1
Views: 305
Reputation: 163858
One thing that can cause this problem is adding web
middleware manually to routes.php
routes in Laravel 5.2.27 or higher.
Upvotes: 1