“Reglas de Laravel” Código de respuesta

Validación por correo electrónico en Laravel

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

PHP Artisan Make: Solicitud

php artisan make:request User\CreateUserRequest 
Encouraging Echidna

Si algún error en Blade Laravel

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

Errores de validación de retorno de Laravel

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

Reglas de Laravel

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

Reglas de Laravel

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

Respuestas similares a “Reglas de Laravel”

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código