“Message personnalisé de la validation Laravel” Réponses codées

Comment afficher l'erreur de validation dans Laravel Blade

@if($errors->any())
    <div class="alert alert-danger">
        <p><strong>Opps Something went wrong</strong></p>
        <ul>
        @foreach ($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
        </ul>
    </div>
@endif

@if(session('success'))
    <div class="alert alert-success">{{session('success')}}</div>
@endif

@if(session('error'))
    <div class="alert alert-danger">{{session('error')}}</div>
@endif
Exuberant Elk

Laravel valide entier entre

'item' => 'required|integer|between:1,10',
Clever Cicada

Message personnalisé de la validation Laravel

public function store()
{
    request()->validate([
        'file' => 'required',
        'type' => 'required'
    ],
    [
        'file.required' => 'You have to choose the file!',
        'type.required' => 'You have to choose type of the file!'
    ]);
}
vintsol

Message personnalisé de la validation Laravel

$this->validate([ // 1st array is field rules
  'userid' =>'required|min:3|max:100',
  'username' =>'required|min:3',
  'password' =>'required|max:15|confirmed',
], [ // 2nd array is the rules custom message
  'required' => 'The :attribute field is mandatory.'
], [ // 3rd array is the fields custom name
  'userid' => 'User ID'
]);
hirohito

Message personnalisé de la validation Laravel

$messsages = [
              'email.required'=>'You cant leave Email field empty',
              'name.required'=>'You cant leave name field empty',
              'name.min'=>'The field has to be :min chars long',
			 ];

	$rules = [
              'email'=>'required|unique:content',
              'name'=>'required|min:3',
			];

$validator = Validator::make($request, $rules,$messsages);
ashik

Message personnalisé de la validation Laravel

$rules = [
  'username' => 'required,unique:Userlogin,username',
  'password' => 'required',
  'email'    => 'required,unique:Userlogin,email'
];

$messages = [
  'required'  => 'The :attribute field is required.',
  'unique'    => ':attribute is already used'
];

$request->validate($rules,$messages);
//only if validation success code below will be executed
vintsol

Réponses similaires à “Message personnalisé de la validation Laravel”

Questions similaires à “Message personnalisé de la validation Laravel”

Plus de réponses similaires à “Message personnalisé de la validation Laravel” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code