🆙 More fixes 🆙

This commit is contained in:
Remco
2026-01-19 23:22:33 +01:00
parent 7f253b5261
commit 35202aa825
10 changed files with 49 additions and 26 deletions
@@ -2,38 +2,46 @@
namespace App\Filament\Traits;
use Str;
use Illuminate\Support\Str;
trait TranslatableResource
{
public static function getNavigationGroup(): ?string
{
$group = property_exists(static::class, 'navigationGroup') ? static::$navigationGroup : null;
$groupStr = is_string($group) ? $group : ($group instanceof \UnitEnum ? $group->name : '');
return __(
sprintf('filament::resources.navigations.%s', static::$navigationGroup),
sprintf('filament::resources.navigations.%s', $groupStr),
);
}
public static function getPluralModelLabel(): string
{
$identifier = property_exists(static::class, 'translateIdentifier') ? static::$translateIdentifier : '';
$identifierStr = is_string($identifier) ? $identifier : ($identifier instanceof \UnitEnum ? $identifier->name : '');
return __(sprintf(
Str::endsWith(static::class, 'RelationManager')
? 'filament::resources.resources.%s.navigation_label'
: 'filament::resources.resources.%s.plural',
static::$translateIdentifier,
$identifierStr,
));
}
public static function getNavigationLabel(): string
{
$identifier = property_exists(static::class, 'translateIdentifier') ? static::$translateIdentifier : '';
$identifierStr = is_string($identifier) ? $identifier : ($identifier instanceof \UnitEnum ? $identifier->name : '');
return __(
sprintf('filament::resources.resources.%s.navigation_label', static::$translateIdentifier),
sprintf('filament::resources.resources.%s.navigation_label', $identifierStr),
);
}
public static function getModelLabel(): string
{
$identifier = property_exists(static::class, 'translateIdentifier') ? static::$translateIdentifier : '';
$identifierStr = is_string($identifier) ? $identifier : ($identifier instanceof \UnitEnum ? $identifier->name : '');
return __(
sprintf('filament::resources.resources.%s.label', static::$translateIdentifier),
sprintf('filament::resources.resources.%s.label', $identifierStr),
);
}
}
@@ -45,10 +45,10 @@ class ArticlesAggregateChart extends ChartWidget
'datasets' => [
[
'label' => $label,
'data' => $data->map(fn (TrendValue $value) => $value->aggregate),
'data' => $data->map(fn ($value) => data_get($value, 'aggregate')),
],
],
'labels' => $data->map(fn (TrendValue $value) => $value->date),
'labels' => $data->map(fn ($value) => data_get($value, 'date')),
];
}
@@ -20,31 +20,31 @@ class TopDashboardOverview extends BaseWidget
protected function getStats(): array
{
return [
Stat::make(__('filament::resources.stats.users_count.title'), Number::format(User::count(), '0', '1', app()->getLocale()))
Stat::make(__('filament::resources.stats.users_count.title'), Number::format(User::count(), 0, 1, app()->getLocale()))
->description(__('filament::resources.stats.users_count.description'))
->chart([20, 20])
->descriptionIcon('heroicon-m-user-group', IconPosition::Before)
->color('success'),
Stat::make(__('filament::resources.stats.furniture_count.title'), Number::format(ItemDefinition::count(), '0', '1', app()->getLocale()))
Stat::make(__('filament::resources.stats.furniture_count.title'), Number::format(ItemDefinition::count(), 0, 1, app()->getLocale()))
->description(__('filament::resources.stats.furniture_count.description'))
->descriptionIcon('heroicon-m-cube', IconPosition::Before)
->chart([20, 20])
->color('success'),
Stat::make(__('filament::resources.stats.rooms_count.title'), Number::format(Room::count(), '0', '1', app()->getLocale()))
Stat::make(__('filament::resources.stats.rooms_count.title'), Number::format(Room::count(), 0, 1, app()->getLocale()))
->description(__('filament::resources.stats.rooms_count.description'))
->descriptionIcon('heroicon-m-building-storefront', IconPosition::Before)
->chart([20, 20])
->color('success'),
Stat::make(__('filament::resources.stats.photos_count.title'), Number::format(CameraWeb::count(), '0', '1', app()->getLocale()))
Stat::make(__('filament::resources.stats.photos_count.title'), Number::format(CameraWeb::count(), 0, 1, app()->getLocale()))
->description(__('filament::resources.stats.photos_count.description'))
->descriptionIcon('heroicon-m-camera', IconPosition::Before)
->chart([20, 20])
->color('success'),
Stat::make(__('filament::resources.stats.badge_count.title'), Number::format(WebsiteBadge::count(), '0', '1', app()->getLocale()))
Stat::make(__('filament::resources.stats.badge_count.title'), Number::format(WebsiteBadge::count(), 0, 1, app()->getLocale()))
->description(__('filament::resources.stats.badge_count.description'))
->descriptionIcon('heroicon-m-gif', IconPosition::Before)
->chart([20, 20])
+10 -9
View File
@@ -35,16 +35,14 @@ if (! function_exists('isDarkColor')) {
if (! function_exists('hasPermission')) {
function hasPermission(string $permission): bool
{
$value = app(PermissionsService::class)->getOrDefault($permission);
return $value === true || $value === 1 || $value === '1';
return app(PermissionsService::class)->getOrDefault($permission);
}
}
if (! function_exists('hasHousekeepingPermission')) {
function hasHousekeepingPermission(string $permission): bool
{
$value = app(HousekeepingPermissionsService::class)->getOrDefault($permission);
return $value === true || $value === 1 || $value === '1';
return app(HousekeepingPermissionsService::class)->getOrDefault($permission);
}
}
@@ -59,9 +57,11 @@ if (! function_exists('findMigration')) {
function findMigration(string $tableName): string
{
static $cache = [];
$cache = is_array($cache) ? $cache : [];
if (isset($cache[$tableName])) {
return $cache[$tableName];
$cached = $cache[$tableName];
return is_string($cached) ? $cached : '';
}
$migrationsPath = database_path('migrations');
@@ -75,8 +75,9 @@ if (! function_exists('findMigration')) {
if ($file->isFile() && $file->getExtension() === 'php') {
$content = @file_get_contents($file->getPathname());
if ($content !== false && str_contains($content, "Schema::create('$tableName'")) {
$cache[$tableName] = $file->getFilename();
return $file->getFilename();
$filename = (string) $file->getFilename();
$cache[$tableName] = $filename;
return $filename;
}
}
}
@@ -110,8 +111,8 @@ if (! function_exists('dropForeignKeyIfExists')) {
->pluck('CONSTRAINT_NAME');
foreach ($foreignKeys as $foreignKey) {
if (! empty($foreignKey)) {
$connection->statement("ALTER TABLE {$table} DROP FOREIGN KEY {$foreignKey}");
if (is_string($foreignKey) && $foreignKey !== '') {
$connection->statement('ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey);
}
}
}
+5 -1
View File
@@ -72,7 +72,6 @@ use App\Models\ChatlogPrivate;
*/
class User extends Authenticatable implements FilamentUser, HasName
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasApiTokens, HasFactory, LogsActivity, Notifiable, TwoFactorAuthenticatable;
public $timestamps = false;
@@ -311,6 +310,11 @@ class User extends Authenticatable implements FilamentUser, HasName
return $this->hasMany(CameraWeb::class);
}
protected static function newFactory(): \Database\Factories\UserFactory
{
return \Database\Factories\UserFactory::new();
}
/**
* @return HasMany<WebsiteUserGuestbook, $this>
*/