How can i do this?

What seems to be the problem:
I want to do this:
When a user fill the form. Is will be unique and return
data for example: This email has been taken from Joe user. How can i get this data please help.

Thanks…

You can validate the inputs like this,

$this->validate([
'email' => 'required,email,unique:users,email,' . $user->id,
]);

if you want to show the user who own this email address, don’t do that for security reasons.

1 Like

Thank you but bro its not real i will use this logic to different place. If you know this can you write

You can write a custom role

$this->validate([
'email' => 'required,email,unique:users,email,' . $user->id, function ($attribute, $value, $fail) {
   $user = User::where('email', $vlaue)->first();
  if ($user) {
     $fail('This ' . $attribute . ' has been taken by ' . $user->name); 
   }
}
]);
1 Like

Bro i got an error. What the problem?
This is my db: image
public function updatedurl()
{
$this->validate([
‘url’ => ‘required,unique:modules_youtube,url’, function ($attribute, $fail) {
$videoUrl= User::where(‘url’, “6LQF1wt9fNI” (Note: This value will be custom veriable))->first();
if ($videoUrl) {
$fail('This ’ . $attribute . ’ has been taken by ’ . $user->name);
}
}
]);
}

Bro its my code:
$this->validate([
'Url' => ['required', Rule::unique('module_youtubes')->where(function ($query) { $getUserId = $query->where('url', $this->Url)->first(); ("I'm getting video data which is exists")
/*When i get the user which is has video already; I'm getting this error No property found for validation: [0]*/ $getUser = User::where('id', $getUserId->id)->first(); dd($getUser); ],]);

https://laravel.com/docs/8.x/validation#using-closures