Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto slug #15

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Filament/Clusters/System/Resources/CompanyResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CompanyResource extends ChaosResource

protected static ?string $model = Company::class;

protected static bool $isScopedToTenant = false;

protected static ?int $navigationSort = 1;

public static function form(Form $form): Form
Expand Down Expand Up @@ -52,6 +54,7 @@ public static function form(Form $form): Form

public static function table(Table $table): Table
{
// todo who can see what (check for roles)
return ChaosTables::make(
static::class,
$table,
Expand Down
13 changes: 4 additions & 9 deletions src/Filament/Clusters/System/Resources/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Forms\Set;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use LaraZeus\Chaos\Filament\ChaosResource;
use LaraZeus\Chaos\Forms\Components\MultiLang;
use LaraZeus\Tartarus\Filament\Clusters\System;
Expand Down Expand Up @@ -40,17 +38,14 @@ public static function form(Form $form): Form
MultiLang::make('name')
->required()
->maxLength(255)
->label(__(static::langFile() . '.name'))
->live(onBlur: true)
->afterStateUpdated(function (Set $set, $state) {
$set('slug.' . app()->getLocale(), Str::slug($state[app()->getLocale()]));
}),
MultiLang::make('slug')
->label(__(static::langFile() . '.name')),
/*MultiLang::make('slug')
->live(onBlur: true)
->hidden()
->label(__(static::langFile() . '.slug'))
->unique(ignorable: fn (?Model $record): ?Model => $record)
->required()
->maxLength(255),
->maxLength(255),*/
Select::make('type')
->label(__(static::langFile() . '.type'))
->columnSpan(2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,15 @@
class CreateTag extends ChaosCreateRecord
{
protected static string $resource = TagResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
$data['slug'] = json_encode(
[
app()->getLocale() => str($data['name'][app()->getLocale()])->slug()->toString(),
]
);

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
class EditTag extends ChaosEditRecord
{
protected static string $resource = TagResource::class;

protected function mutateFormDataBeforeSave(array $data): array
{
$data['slug'] = [];

return $data;
}
}
2 changes: 1 addition & 1 deletion src/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected function defaultProfilePhotoUrl(): string
})->join(' '));

$bgColor = 'BFA577';
if (tenant()->primary_color !== null) {
if (tenant()?->primary_color !== null) {
$colorName = str(tenant()->primary_color)->title();
$color = constant("Filament\Support\Colors\Color::$colorName");
$bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', '');
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Tag extends \Spatie\Tags\Tag
use ForCompany;
use SoftDeletes;

public function getCasts(): array
protected function casts(): array
{
return [
'type' => TartarusPlugin::getModel('TagType'),
Expand Down