Skip to content

Commit

Permalink
fix slug issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Jan 17, 2024
1 parent ab3fdfc commit 38b0482
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/Concerns/HasSlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public function generateSlug(): string
$base = $slug = Str::slug($this->{$this->getSlugFieldSource()});
$suffix = 1;


while ($this->slugAlreadyUsed($slug)) {
$slug = Str::slug($base . '_' . $suffix++);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ protected function getTableActions(): array
DeactivateOrganizationAction::make(),
];
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function getTableRecordUrlUsing(): \Closure

protected function paginateTableQuery(Builder $query): Paginator
{
return $query->simplePaginate(
return $query->paginate(
$this->getTableRecordsPerPage() == -1 ? $query->count() : $this->getTableRecordsPerPage(),
['*'],
$this->getTablePaginationPageName(),
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public static function table(Table $table): Table
Tables\Actions\EditAction::make(),

])
->defaultSort('id', 'desc')
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
])
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function store(RegistrationRequest $request): RedirectResponse
if ($user->hasRole(UserRole::ADMIN)) {
$attributes['ngo']['status'] = OrganizationStatus::draft;
$attributes['ngo']['slug'] = Str::slug($attributes['ngo']['name']);
dd(collect($attributes['ngo'])->toJson());

$organization = Organization::create($attributes['ngo']);

Expand Down
7 changes: 4 additions & 3 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Organization extends Model implements HasMedia
protected $fillable = [
'name',
'cif',
// 'slug',
'description',
'address',
'contact_person',
Expand Down Expand Up @@ -82,6 +81,8 @@ class Organization extends Model implements HasMedia
'statute',
];

private string $slugFieldSource = 'name';

public function projects(): HasMany
{
return $this->hasMany(Project::class)->without('organization');
Expand Down Expand Up @@ -166,12 +167,12 @@ public function scopeWhereDoesntHaveProjects(Builder $query): Builder

public function scopeWhereHasActiveProjects(Builder $query): Builder
{
return $query->whereRelation('projects', 'status', ProjectStatus::active);
return $query->whereRelation('projects', 'status', ProjectStatus::approved);
}

public function scopeWhereDoesntHaveActiveProjects(Builder $query): Builder
{
return $query->whereRelation('projects', 'status', '!=', ProjectStatus::active);
return $query->whereRelation('projects', 'status', '!=', ProjectStatus::approved);
}

public function scopeWhereHasEuPlatesc(Builder $query): Builder
Expand Down
2 changes: 1 addition & 1 deletion database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function run(): void
->create();

Organization::factory()
->count(5)
->count(50)
->approved()
->create();

Expand Down

0 comments on commit 38b0482

Please sign in to comment.