user(); } protected function actor(Request $request): User { return $request->user(); } protected function wooMember(Request $request): ?WooStoreMember { return $request->attributes->get('woo.member'); } /** @return list|null */ protected function storeScope(Request $request): ?array { return $request->attributes->get('woo.storeIds'); } protected function isStoreOwner(Request $request): bool { return $this->wooMember($request) === null; } protected function currentStore(Request $request): ?WooStore { return app(CurrentWooStore::class)->resolve( $this->accountUser($request), $this->storeScope($request), ); } protected function currentStoreOrFail(Request $request): WooStore { $store = $this->currentStore($request); abort_if(! $store, 404, 'Connect a WooCommerce store to continue.'); return $store; } protected function authorizedStore(Request $request, int $storeId): WooStore { $store = WooStore::query() ->where('user_id', $this->accountUser($request)->id) ->whereKey($storeId) ->where('status', WooStore::STATUS_ACTIVE) ->firstOrFail(); abort_unless( app(\App\Services\Woo\WooStoreMemberResolver::class) ->canAccessStore($this->actor($request), (string) $this->accountUser($request)->public_id, $store->id), 404, ); return $store; } }