“Laravel Rules” Réponses codées

Validation des e-mails dans Laravel

'email' => 'required|email|unique:users,email',
//@sujay
$uj@y

PHP Artisan Make: Demande

php artisan make:request User\CreateUserRequest 
Encouraging Echidna

Si une erreur dans Blade Laravel

 @if ($errors->any())
     @foreach ($errors->all() as $error)
         <div>{{$error}}</div>
     @endforeach
 @endif
Zamir

erreurs de validation de retour de Laravel

@if($errors->any())
   @foreach ($errors->all() as $error)
      <div>{{ $error }}</div>
  @endforeach
@endif
Xfantasia

Laravel Rules

public function store(Request $request) {
    $this->validate($request, [
        'name' => 'required|string',
        'body' => 'required|string',
        'publish_at' => 'required|date_format:Y-m-d H:i:s'
    ], [
      'name.required' => 'A article name is required',
      'body.required'  => 'A article body is required',
      'publish_at.date_format' => 'The publish at date is not in the correct format.'
    ]);
 
    // The request validated and this code will get run
    ...
}
Itchy Ibis

Laravel Rules

public function store(Request $request) {
    $this->validate($request, [
        'name' => 'required|string',
        'body' => 'required|string',
        'publish_at' => 'required|date_format:Y-m-d H:i:s'
    ], [
      'name.required' => 'A article name is required',
      'body.required'  => 'A article body is required',
      'publish_at.date_format' => 'The publish at date is not in the correct format.'
    ]);
 
    // The request validated and this code will get run
    ...
}
Itchy Ibis

Réponses similaires à “Laravel Rules”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code