From 3822eb1e2b837e81ade07fb6dd847b9aff0f7f79 Mon Sep 17 00:00:00 2001 From: mahdihty Date: Sat, 17 Apr 2021 14:53:01 +0430 Subject: [PATCH] add auth and two other method to authcontroller --- app/Http/Controllers/AuthController.php | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index bdd354d..29966ad 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Http\Resources\UserResource; use App\Models\Business; use App\Models\User; use App\Notifications\DBNotification; @@ -279,4 +280,34 @@ class AuthController extends Controller ])); } } + + public function auth() + { + return new UserResource(Auth::user()); + } + + public function authWithInfo() + { + return [ + 'auth' => new UserResource(Auth::user()), + 'businesses' => Auth::user()->businesses->keyBy('id') ->map(fn($b, $bid) => Business::info($bid)) + ]; + } + + public function updateFcmToken(Request $request) + { + Auth::user()->fingerprints()->where( + [ + ['agent', request()->getAgent()], + ['ip', request()->getClientIp()], + ['os', request()->getOS()], + ['latitude', \request()->getLocation()->getAttribute('lat')], + ['longitude', \request()->getLocation()->getAttribute('lon')], + ] + )->firstOrFail()->update([ + 'fcm_token' => $request->fcm_token + ]); + return $this->authWithInfo(); + } + }