Rules in TextInput breaks server.

When i add the following rule to an TextInput and i try to save the form is breaks the server and i need to restart it.

  Forms\Components\TextInput::make('slug')
      ->hint('Translatable')
      ->hintColor('primary')
      ->hintIcon('heroicon-m-language')
      ->disabled()
      ->rules([
          function () {
              return function ($value, Closure $fail, $livewire) {
                  // Check if slug belongs to currrent page
                  $count = Sitemap::all()
                      ->where('slug', '=', $value)
                      ->where('resource_id', $livewire->record->getAttribute('id'))
                      ->where('resource_type', 'page')
                      ->count();
                  if ($count > 0) {
                      return;
                  }

                  // Check if slug already exists in another resource
                  $countExists = Sitemap::all()
                      ->where('slug', '=', $value)
                      ->count();
                  if ($countExists > 0) {
                      $fail("The slug already exists in another resource");
                  }
              };
          },
      ])
      ->maxLength(255),


Can someone point me out what I am doing wrong?
Was this page helpful?