In controller I have added a login method and when the login will success it will return the data only those which are included in a resource. But it is returning all data. It was working till morning but now it's not.
In my controller I have done this
public function merchant_login(Request $request): JsonResponse
{
$validator = Validator::make($request->all(), [
'email' => 'required',
'password' => 'required',
]);
if ($validator->fails()) {
return response()->json(['error' => $validator->errors()], 422);
}
$user = User::query()->with('shop')
->where('role', User::MERCHANT)
->where('email', $request->input('email'))
->orWhere('phone', User::normalizePhone($request->input('email')))
->orWhere('phone', User::removeCode($request->input('email')))
->first();
if($user && Hash::check($request->input('password'), $user->password)) {
$date = differenceDate($user->getRawOriginal('created_at'));
if($user->payment_status == User::UNPAID && $date) {
$user->status = User::STATUS_EXPIRED;
$user->save();
return $this->sendApiResponse('', 'Sorry Your trial period has expired', 'Unauthorized');
}
$token = $this->generateToken($user->id, $request->header('ipaddress'), $request->header('browsername'));
return $this->sendApiResponse(new MerchantResource($user), 'Successfully logged in', '', ['token' => $token]);
} else {
return $this->sendApiResponse('', 'Unable to sign in with given credentials', 'Unauthorized');
}
}
when success it will return some data in my resource i have done
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'domain' => $this->shop->domain,
'email' => $this->email,
'phone' => $this->phone,
'role' => $this->role,
'shop_id' => $this->shop->shop_id,
'avatar' => $this->avatar,
'phone_verified' => $this->phone_verified_at !== null,
];
}
but it returning all data
"id": 2,
"name": "Tess Bashirian",
"email": "merchant33717@gmail.com",
"phone": "267.741.6795",
"address": null,
"role": "merchant",
"otp": null,
"status": "active",
"email_verified_at": "2023-03-29T14:32:03.000000Z",
"phone_verified_at": "2023-03-27 14:32:03",
"created_at": "29th March 2023, 2:32 pm",
"updated_at": "2023-03-29T14:47:28.000000Z",
"payment_status": "paid",
"avatar": "http://localhost:8000/images/profile.png",
"shop": {
"id": 1,
"name": "Dr. Emmanuel Heaney",
"domain": "dr.-emmanuel-heaney",
"shop_id": "686444",
"address": "530 Kareem Well Suite 460\nMinnieland, ID 58513-7016",
"email": null,
"phone": null,
"about_us": null,
"privacy_policy": null,
"tos": null,
"shop_meta_title": null,
"shop_meta_description": null,
"user_id": 2,
"created_at": "2023-03-29T14:32:04.000000Z",
"updated_at": "2023-03-29T14:32:04.000000Z",
"sms_balance": 0,
"courier_balance": 0,
"sms_sent": 0
}
I didn't find any solution