Redirect to new slug after updating tenant name

Hi. I have the below EditTenantProfile set up just like the docs:
//EditTeamProfile.php
class EditTeamProfile extends EditTenantProfile
{
public static function getLabel(): string
{
return 'Team profile';
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name'),
// ...
]);
}
}
//EditTeamProfile.php
class EditTeamProfile extends EditTenantProfile
{
public static function getLabel(): string
{
return 'Team profile';
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name'),
// ...
]);
}
}
Now, I have a slug column on my Team model, that is automatically set based on the name:
//Team.php
public static function boot()
{
parent::boot();

static::saving(function ($model) {
$model->slug = Str::of($model->name)->slug('-');
});
}
//Team.php
public static function boot()
{
parent::boot();

static::saving(function ($model) {
$model->slug = Str::of($model->name)->slug('-');
});
}
Now, currently, when updating the name of the team, it will result in a 404 page (since the slug is now updated, and thus the old slug no longer exists). I added this method on the EditTeamProfile.php, but I am unsure if there are other easier ways of doing this?
protected function getRedirectUrl(): ?string
{
//Update as the slug will be different
return route('filament.app.tenant.profile', ['tenant' => $this->tenant->slug]);
}
protected function getRedirectUrl(): ?string
{
//Update as the slug will be different
return route('filament.app.tenant.profile', ['tenant' => $this->tenant->slug]);
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server