-
app/Models/Credentials.php
Open in GitHubuse Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Casts\AsEncryptedArrayObject; use Illuminate\Database\Eloquent\Model; class Credentials extends Model { // ... public function scopeCanBeUsedByTeam(Builder $query, Team $team) { $query->where(function (Builder $credentialsQuery) use ($team) { $credentialsQuery->whereNull('team_id')->orWhere('team_id', $team->id); }); $query->where(function (Builder $credentialsQuery) use ($team) { $credentialsQuery->whereHas('user.ownedTeams', fn (Builder $ownedTeams) => $ownedTeams->where($ownedTeams->qualifyColumn('id'), $team->id)); $credentialsQuery->orWhereHas('user.teams', fn (Builder $teams) => $teams->where($teams->qualifyColumn('id'), $team->id)); }); } // ... }
-
app/Http/Controllers/ServerController.php
Open in GitHubuse App\Models\Credentials; use App\Provider; use Illuminate\Http\Request; class ServerController extends Controller { public function create(Request $request) { // ... $credentials = $this->user() ->credentials() ->provider(Provider::forServers()) ->canBeUsedByTeam($this->team()) ->select('id', 'name', 'provider') ->get() ->mapWithKeys(fn (Credentials $credentials) => [$credentials->id => $credentials->nameWithProvider]); // ... } // ... }