laravel form request unique code example
Example 1: 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)
]
];
}
Example 2: laravel validation
public function store(Request $request)
{
$validatedData = $request->validate([
'title' => 'required|unique:posts|max:255',
'body' => 'required',
]);
}
Example 3: laravel unique validation
unique:table,column,except,idColumn
'email' => 'unique:users,email_address,' . $userId,
'email' => 'unique:users,email_address',