Browse Source

add auth and two other method to authcontroller

mahdi
mahdihty 4 years ago
parent
commit
3822eb1e2b
  1. 31
      app/Http/Controllers/AuthController.php

31
app/Http/Controllers/AuthController.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Resources\UserResource;
use App\Models\Business; use App\Models\Business;
use App\Models\User; use App\Models\User;
use App\Notifications\DBNotification; 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();
}
} }
Loading…
Cancel
Save