Search
 
SCRIPT & CODE EXAMPLE
 

PHP

unique validation on update laravel

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

how to validate use unique in laravel 8 controller

 $request->validate([
            'name' => 'required',
            'email' => 'required|unique:Student',
            'password' => 'required|min:6',
            'mobile' => 'required',
            'address' => 'required',
        ]);
//unique:table_name
Comment

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...
}
Comment

set unique value validation for laravel form request

use IlluminateValidationRule;

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

Laravel: Validation unique on update

Just a side note, most answers to this question talk about email_address while in Laravel's inbuilt auth system, the email field name is just email. Here is an example how you can validate a unique field, i.e. an email on the update:

In a Form Request, you do like this:

public function rules()
{
  return [
      'email' => 'required|email|unique:users,email,'.$this->user->id,
  ];
}
Or if you are validating your data in a controller directly:

public function update(Request $request, User $user)
{
  $request->validate([
      'email' => 'required|email|unique:users,email,'.$user->id,
  ]);
}
Update: If you are updating the signed in user and aren't injecting the User model into your route, you may encounter undefined property when accessing id on $this->user. In that case, use:

public function rules()
    {
      return [
          'email' => 'required|email|unique:users,email,'.$this->user()->id,
      ];
    }
A more elegant way since Laravel 5.7 is:

public function rules()
{
    return [
        'email' => ['required', 'email', IlluminateValidationRule::unique('users')->ignore($this->user()->id)]
    ];
}
Comment

laravel unique validation

unique:table,column,except,idColumn

############## Example : ################

############### For Updating  
//rules
'email' => 'unique:users,email_address,' . $userId,

############### For Creating 
//rules
'email' => 'unique:users,email_address',
Comment

laravel validate form data unique

'username' => ['required', Rule::unique('users', 'username')],
Comment

unique validation laravel

<?php
  
namespace AppHttpRequests;
  
use IlluminateFoundationHttpFormRequest;
  
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'
            ];
    }
}
Comment

Laravel unique with Validation rule

'name'        => 'required|max:150|unique:course_lessons,name,NULL,id,course_id,' . request('course_id'),
 "<input_filed_name>" => "valiadtionRule"|"ValidationRule"|"unique:<tableName>,<validateableField>,<ignoreableID>,<tablePrimaryKey>,<column1>,<column1Value>,<column2>,<column2Value>"
Comment

laravel validation unique in edit

protected $rules = [
    'email_address' => 'sometimes|required|email|unique:users',
    ..
];
Comment

laravel validation unique in edit

...
$rules = User::$rules;
$rules['email_address'] = $rules['email_address'] . ',id,' . $id;
$validationCertificate  = Validator::make($input, $rules);
Comment

Laravel 9 Unique Validation on Update

 // Using Form Request

 	public function rules()
    {
        return [
            'name'  => [
                'required',
                Rule::unique('posts')->ignore($this->id)
            ],
          ];
    }
Comment

PREVIOUS NEXT
Code Example
Php :: sanctum 
Php :: laravel composer sanctum 
Php :: Parse error: syntax error, unexpected token "{" in C:xampphtdocsloginsystem1welcome.php on line 3 
Php :: new order email filter woocommerce 
Php :: laravel creat new model 
Php :: upload image to database laravel 8 
Php :: php function to minify javascript and css 
Php :: laravel eloquent multiple join 
Php :: run composer with specific php version 
Php :: yii2 migration --fields foreign 
Php :: laravel seeder with relationships 
Php :: Add Text After or Before on the Shop Page/Archive Page 
Php :: laravel migration longtext length 
Php :: Regex to remove span tags using php [duplicate] 
Php :: permutation and combination program in php 
Php :: wordpress highlight text excerpt 
Php :: italic text in laravel notification 
Php :: is resource php 8 
Php :: install composer laravel 
Php :: accept method in jquery 
Php :: laravel reoute return string 
Php :: static function php 
Php :: what is php artisan 
Php :: wordpress change email new user template 
Php :: php configuration file location in centos 8 
Php :: php division 
Php :: require_once different on server 
Php :: php const scope 
Php :: php convert path from server url to link 
Php :: how to define a function in scheme 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =