You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 line
812B

  1. <?php
  2. namespace App\Http\Controllers\Web\Auth;
  3. use App\Exceptions\AppCommonException;
  4. use App\Sessions\SessionUser;
  5. use Illuminate\Support\Facades\Auth;
  6. trait Me
  7. {
  8. public function me(): array
  9. {
  10. if (!Auth::check()) {
  11. throw new AppCommonException("Me失敗");
  12. }
  13. $sessionUser = SessionUser::instance();
  14. $ret = Auth::user()->toArray();
  15. if ($sessionUser->isSwtiched()) {
  16. $ret['switched_user_id'] = $sessionUser->user()->id;
  17. $ret['switched_role'] = $sessionUser->user()->role;
  18. $ret['switched_name'] = $sessionUser->user()->name;
  19. } else {
  20. $ret['switched_user_id'] = null;
  21. $ret['switched_role'] = null;
  22. $ret['switched_name'] = null;
  23. }
  24. return $ret;
  25. }
  26. }