-
app/Policies/WorkspacePolicy.php
Open in GitHubuse App\Models\User; use App\Models\Workspace; class WorkspacePolicy { public function reachedLinkLimit(?User $user, Workspace $workspace): bool { return !$workspace->usage()['links']['reached_limit']; } /** * Determine if the user has reached the events limit. */ public function reachedEventLimit(?User $user, Workspace $workspace): bool { return !$workspace->usage()['events']['reached_limit']; } public function reachedDomainLimit(?User $user, Workspace $workspace): bool { return !$workspace->usage()['domains']['reached_limit']; } public function reachedTagLimit(?User $user, Workspace $workspace): bool { return !$workspace->usage()['tags']['reached_limit']; } public function reachedUserLimit(?User $user, Workspace $workspace): bool { return !$workspace->usage()['users']['reached_limit']; } }
-
app/Http/Controllers/LinkController.php
Open in GitHubuse Illuminate\Support\Facades\Gate; use App\Http\Requests\Link\CreateRequest; class LinkController extends Controller { // ... public function store(CreateRequest $request) { $user = auth()->user(); $workspace = $user->currentWorkspace; $response = Gate::inspect('reached-link-limit', $workspace); if (!$response->allowed()) { session()->flash('flash.banner', 'You have reached the limit of links, please upgrade your plan.'); session()->flash('flash.bannerStyle', 'danger'); return back(); } // ... } // ... }