Skip to content

Instantly share code, notes, and snippets.

View daika7ana's full-sized avatar

Dan-Radu Pana daika7ana

  • Constanta, Romania
  • 15:28 (UTC +03:00)
View GitHub Profile
@daika7ana
daika7ana / GeneratesUniqueTeamSlugsForTest.php
Created April 10, 2026 10:58
GeneratesUniqueTeamSlugsForTest
trait GeneratesUniqueTeamSlugsForTest
{
protected static function generateUniqueTeamSlug(string $name, ?int $excludeId = null): string
{
$defaultSlug = Str::slug($name);
$query = static::withTrashed()
->whereRaw('slug regexp ?', ['^' . preg_quote($defaultSlug) . '(-[0-9]+)?$'])
->when($excludeId, fn ($query) => $query->where('id', '!=', $excludeId));