I want to pass custom validation messages to my view using a custom request when storing a role.
I have create a new Request called StoreRoleRequest
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Contracts\Validation\Validator;
class StoreRoleRequest extends Request
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'name' => 'required'
];
}
protected function formatErrors(Validator $validator)
{
return $validator->errors()->all();
}
public function messages()
{
return [
'name.required' => 'the name of the Role is mandatory',
];
}
}
And then pass this custom Request to my store function in the RoleController
like this:
public function store(StoreRoleRequest $request)
{
Role::create($request->all());
return redirect(route('role.index'));
}
I have a view that show the create role form where the validation seems to work properly but without showing me error even if i call them into the view like this:
{!! Former::open()->action(route('role.store')) !!}
@if (count($errors->all()))
<div class="alert alert-danger">
@foreach ($errors->all() as $error)
<li></li>
@endforeach
</div>
@endif
{!! Former::text('name')->label('Groupe name') !!}
{!! Former::text('display_name')->label('Displayed name') !!}
{!! Former::text('description')->label('Description') !!}
{!! Former::actions( Button::primary('Save')->submit(),
Button::warning('Clear')->reset() ,
Button::danger('Close')->asLinkTo('#')->withAttributes(['data-dismiss' => 'modal'])
)!!}
{!! Former::close() !!}
Has anyone an idea why the errors doesn't appear into the view ? am I looping something inside the custom Request ?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SRy6z3
via IFTTT
Aucun commentaire:
Enregistrer un commentaire