Add Unique Validation On A Condition In Request Validation Laravel Code Example


Example 1: laravel unique validation

/**  * 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... }

Example 2: set unique value validation for laravel form request

use Illuminate\Validation\Rule;  public function rules() {     return [ 	    'title' => [ 		    'required', 		    Rule::unique('posts', 'title')->ignore($this->post) 	    ]     ];  }

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable