I don't understand why Laravel don't send me validation error and redirects me to the view with 302 error.
I just have simple forms in the view which just send this :
@else
<div class="md-form input-group">
<input type="hidden" name="route_name" value="">
<input type="hidden" name="href" value="">
<input pattern="[a-zA-Zéè \-]{3,35}" required class="form-control" type="text" name="title"
id="linkTitle"
value=""
placeholder="Ajoutez ici un titre à ce lien pour le rendre disponibles pour les menus">
<span class="input-group-btn">
<button type="button"
class="btn btn-default ml-2 btnUpdateLink">Ajouter</button>
</span>
</div>
@endif
the forms sends data to my store method :
public function store(LinkRequest $request)
{
//dd($request->all());
try{
Link::create($request->all());
return redirect(route('Permission.index'))->with('success-message','Lien crée');
}catch (Exception $e){
$errorCode = $e->errorInfo[1];
dd($errorCode);
if($errorCode == 1062){
return redirect(route('Link.index'))
->with('error_message','Un lien existe déjà avec ce titre')
->with('create_name',$request->get('title'));
}
}
}
and here is my LinkRequest class :
public function rules()
{
return [
'title'=> array(
'required',
'max:35',
'unique:links,title,'.$this->Link,
'regex:[a-zA-Zéè]',
),
'route_name'=>array(
'required'
),
'href'=>array(
'required'
),
];
}
Thanks for your help !
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire