“Validation unique Laravel” Réponses codées

Validation unique sur la mise à jour Laravel

public function rules()
{
  return [
      'email' => 'required|email|unique:users,email,'.$this->user->id,
  ];
}
Fine Fly

Laravel génère un jeton unique

use Illuminate\Support\Str;

public function yourFunction(){
 $var = Str::random(32);

 dd($var);
}
Victorious Vendace

Si une erreur dans Blade Laravel

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

Laravel Validation unique

/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */

public function store(Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);

    // The blog post is valid...
}
Handsome Hawk

Laravel Validator fait un message personnalisé

$rules = [
        'name' => 'required',
        'email' => 'required|email',
        'message' => 'required|max:250',
    ];

    $customMessages = [
        'required' => 'The :attribute field is required.'
    ];

    $this->validate($request, $rules, $customMessages);
Clever Constrictor

Validation unique Laravel

<?php
  
namespace App\Http\Requests;
  
use Illuminate\Foundation\Http\FormRequest;
  
class StoreUserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    } 
  
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
                'name' => 'required',
                'username' => 'required|min:8',
                'email'=>'required|email|unique:users,email,NULL,id,deleted_at,NULL'
            ];
    }
}
Irfan

Réponses similaires à “Validation unique Laravel”

Questions similaires à “Validation unique Laravel”

Plus de réponses similaires à “Validation unique Laravel” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code