Just think, how does you believe the system know if that input is unique?

|
Joice 2021-01-25 19:54:55
Joice 2021-01-25 19:53:58

Y getting this error for mobile number unique validation

Joice 2021-01-25 19:55:50
Email unique validation works fine..it will show error that email has been already registered..but for phone ..its throwing sql duplicate constraint violation error
Joice 2021-01-25 19:56:07
Anybody please help
M.A 2021-01-25 20:03:46
Joice 2021-01-25 19:53:58

Did you google it?

Joice 2021-01-25 20:04:12
Yes ..but not getting the solution i want
Joice 2021-01-25 20:04:24
M.A 2021-01-25 20:03:46
Did you google it?

Please help me

Joice 2021-01-25 20:04:38
public function store(Request $request)
{
$this->validate($request, [
‘name’ => ‘required|max:255′,
’email’ => ‘required|unique:users|email|max:255’,
‘avatar’ => ‘image|max:3072’,
‘password’ => ‘required|min:6|confirmed’,
‘phone’ => ‘required|string|min:10’,

],[
‘phone.unique’ => ‘The phone number is already registered with us’

]);
try {
$users_create_permission = check_permission(‘userscreate’,Auth::user()->role_id);
if($users_create_permission==1) {
// $User = $request->all();

$User[‘phone’] = “+”.$request->phone1.$request->phone;
$User[‘password’] = bcrypt($request->password);
$url = env(‘DO_SPACES_ENDPOINT’) . ‘/’ . env(‘DO_SPACES_BUCKET’) . ‘/’;
if($request->hasFile(‘avatar’)) {
// $User[‘avatar’] = (‘storage/’.$request->avatar->store(‘user/profile’));
$image = $request->file(‘avatar’);
$name = str_slug($image->getClientOriginalName() . uniqid()) . ‘.’ . $image->getClientOriginalExtension();
$filePath = ‘images/B2C/’ . $name;
Storage::disk(‘do_spaces’)->put($filePath, file_get_contents($image));
$User[‘avatar’] = $url . $filePath;
}
$User[‘latitude’] = 0;
$User[‘longitude’] = 0;
$User = User::create($User);

// comments on 28/09/2019
$User->notify(new UserRegisteredNotification($User));
return back()->with(‘flash_success’,trans(‘user.created_success’,[‘name’=>$User->name]));
}else{
return back()->with(‘flash_error’,’You have no permission for this task’);
}
} catch (Exception $e) {
// return redirect()->route(‘admin.users.index’)->with(‘flash_error’, ‘Whoops! something went wrong.’);
print_r($e->getMessage());
exit;
return back()->with(‘flash_error’, ‘Whoops! something went wrong.’);
}
}

Joice 2021-01-25 20:04:48
This is the code
meetlunkad 2021-01-25 20:21:06
laravel_discuss-67698.jpg

meetlunkad 2021-01-25 20:21:16
This is how i am return json
meetlunkad 2021-01-25 20:21:33
meetlunkad 2021-01-25 17:09:19
This is my datatable but now in laravel i want one fixed row – opening balance as it does not exists in database how may i add it ?

Please help me
I want one row of opening balance

Joice 2021-01-25 20:22:03
Joice 2021-01-25 19:53:58

Anybody please helpp

DesolatorMagno 2021-01-25 20:24:24
Joice 2021-01-25 20:04:38
public function store(Request $request)
{
$this->validate($request, [
‘name’ => ‘required|max:255′,
’email’ => ‘required|unique:users|email|max:255’,
‘avatar’ => ‘image|max:3072’,
‘password’ => ‘required|min:6|confirmed’,
‘phone’ => ‘required|string|min:10’,

],[
‘phone.unique’ => ‘The phone number is already registered with us’

]);
try {
$users_create_permission = check_permission(‘userscreate’,Auth::user()->role_id);
if($users_create_permission==1) {
// $User = $request->all();

$User[‘phone’] = “+”.$request->phone1.$request->phone;
$User[‘password’] = bcrypt($request->password);
$url = env(‘DO_SPACES_ENDPOINT’) . ‘/’ . env(‘DO_SPACES_BUCKET’) . ‘/’;
if($request->hasFile(‘avatar’)) {
// $User[‘avatar’] = (‘storage/’.$request->avatar->store(‘user/profile’));
$image = $request->file(‘avatar’);
$name = str_slug($image->getClientOriginalName() . uniqid()) . ‘.’ . $image->getClientOriginalExtension();
$filePath = ‘images/B2C/’ . $name;
Storage::disk(‘do_spaces’)->put($filePath, file_get_contents($image));
$User[‘avatar’] = $url . $filePath;
}
$User[‘latitude’] = 0;
$User[‘longitude’] = 0;
$User = User::create($User);

// comments on 28/09/2019
$User->notify(new UserRegisteredNotification($User));
return back()->with(‘flash_success’,trans(‘user.created_success’,[‘name’=>$User->name]));
}else{
return back()->with(‘flash_error’,’You have no permission for this task’);
}
} catch (Exception $e) {
// return redirect()->route(‘admin.users.index’)->with(‘flash_error’, ‘Whoops! something went wrong.’);
print_r($e->getMessage());
exit;
return back()->with(‘flash_error’, ‘Whoops! something went wrong.’);
}
}

I don’t see the unique rule applied to phone, so is working fine.

Joice 2021-01-25 20:25:21
public function store(Request $request)
{
$this->validate($request, [
‘name’ => ‘required|max:255′,
’email’ => ‘required|unique:users|email|max:255’,
‘avatar’ => ‘image|max:3072’,
‘password’ => ‘required|min:6|confirmed’,
‘phone’ => ‘required|unique|string|min:10’,

],[
‘phone.unique’ => ‘The phone number is already registered with us’

]);
try {
$users_create_permission = check_permission(‘userscreate’,Auth::user()->role_id);
if($users_create_permission==1) {
// $User = $request->all();

$User[‘phone’] = “+”.$request->phone1.$request->phone;
$User[‘password’] = bcrypt($request->password);
$url = env(‘DO_SPACES_ENDPOINT’) . ‘/’ . env(‘DO_SPACES_BUCKET’) . ‘/’;
if($request->hasFile(‘avatar’)) {
// $User[‘avatar’] = (‘storage/’.$request->avatar->store(‘user/profile’));
$image = $request->file(‘avatar’);
$name = str_slug($image->getClientOriginalName() . uniqid()) . ‘.’ . $image->getClientOriginalExtension();
$filePath = ‘images/B2C/’ . $name;
Storage::disk(‘do_spaces’)->put($filePath, file_get_contents($image));
$User[‘avatar’] = $url . $filePath;
}
$User[‘latitude’] = 0;
$User[‘longitude’] = 0;
$User = User::create($User);

// comments on 28/09/2019
$User->notify(new UserRegisteredNotification($User));
return back()->with(‘flash_success’,trans(‘user.created_success’,[‘name’=>$User->name]));
}else{
return back()->with(‘flash_error’,’You have no permission for this task’);
}
} catch (Exception $e) {
// return redirect()->route(‘admin.users.index’)->with(‘flash_error’, ‘Whoops! something went wrong.’);
print_r($e->getMessage());
exit;
return back()->with(‘flash_error’, ‘Whoops! something went wrong.’);
}
}

Joice 2021-01-25 20:25:34
DesolatorMagno 2021-01-25 20:24:24
I don’t see the unique rule applied to phone, so is working fine.

Sorry this was the code

Joice 2021-01-25 20:25:45
Please help
DesolatorMagno 2021-01-25 20:26:00
Did you tried reading how unique work?
Joice 2021-01-25 20:26:09
Yes…
Joice 2021-01-25 20:26:21
The unique for email works fine in this code
DesolatorMagno 2021-01-25 20:26:36
But, is different.
Joice 2021-01-25 20:26:43
But for phone ..its show that sql duplicate constraints problem
Joice 2021-01-25 20:26:55
DesolatorMagno 2021-01-25 20:26:36
But, is different.

What

Joice 2021-01-25 20:27:29
Joice 2021-01-25 19:53:58

When giving same phone number its throwing this error

DesolatorMagno 2021-01-25 20:29:15
https://laravel.com/docs/8.x/validation#rule-unique
DesolatorMagno 2021-01-25 20:29:54
You are doing it wrong, if you read the documentation and see the email example you could understand.
Joice 2021-01-25 20:30:09
DesolatorMagno 2021-01-25 20:29:54
You are doing it wrong, if you read the documentation and see the email example you could understand.

Can you please say how

Joice 2021-01-25 20:30:20
I was on this for past 5hours
Joice 2021-01-25 20:30:30
Please help me
DesolatorMagno 2021-01-25 20:30:38
DesolatorMagno 2021-01-25 20:29:15
https://laravel.com/docs/8.x/validation#rule-unique

Just read this.

Joice 2021-01-25 20:31:16
Had already read this
Joice 2021-01-25 20:31:27
But not understanding my mistake
DesolatorMagno 2021-01-25 20:32:18
Just think, how does you believe the system know if that input is unique?
Joice 2021-01-25 20:32:43
It will check the db
Joice 2021-01-25 20:33:11
Sir,the email field validation is working fine in that code
DesolatorMagno 2021-01-25 20:33:16
Exactly.
|