Skip to content

Filament updates #86

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

Merged
merged 8 commits into from
Oct 28, 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
2 changes: 2 additions & 0 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class UserResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-users';

protected static ?string $recordTitleAttribute = 'full_name';

public static function form(Form $form): Form
{
return $form
Expand Down
8 changes: 8 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
if ($this->app->environment('local')) {
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
$this->app->register(TelescopeServiceProvider::class);
}
}

public function boot(): void
{
JsonResource::withoutWrapping();
Expand Down
18 changes: 17 additions & 1 deletion app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
namespace App\Providers\Filament;

use Althinect\FilamentSpatieRolesPermissions\FilamentSpatieRolesPermissionsPlugin;
use App\Enums\Role;
use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;
use pxlrbt\FilamentEnvironmentIndicator\EnvironmentIndicatorPlugin;
use Stephenjude\FilamentDebugger\DebuggerPlugin;

class AdminPanelProvider extends PanelProvider
{
Expand All @@ -35,7 +39,19 @@ public function panel(Panel $panel): Panel
Pages\Dashboard::class,
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->plugin(FilamentSpatieRolesPermissionsPlugin::make())
->plugins([
FilamentSpatieRolesPermissionsPlugin::make(),
EnvironmentIndicatorPlugin::make()
->visible(fn () => \auth()->user()?->hasRole(Role::SUPER_ADMIN) && \app()->environment() !== 'production')
->color(fn () => match (app()->environment()) {
'production' => Color::Green,
'staging' => Color::Blue,
'local' => Color::Red,
default => Color::Gray,
}),
DebuggerPlugin::make()
->authorize(fn () => \auth()->user()?->hasRole(Role::SUPER_ADMIN) && \app()->environment() !== 'production'),
])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
Expand Down
64 changes: 64 additions & 0 deletions app/Providers/TelescopeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Telescope;
use Laravel\Telescope\TelescopeApplicationServiceProvider;

class TelescopeServiceProvider extends TelescopeApplicationServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
// Telescope::night();

$this->hideSensitiveRequestDetails();

$isLocal = $this->app->environment('local');

Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
return $isLocal ||
$entry->isReportableException() ||
$entry->isFailedRequest() ||
$entry->isFailedJob() ||
$entry->isScheduledTask() ||
$entry->hasMonitoredTag();
});
}

/**
* Prevent sensitive request details from being logged by Telescope.
*/
protected function hideSensitiveRequestDetails(): void
{
if ($this->app->environment('local')) {
return;
}

Telescope::hideRequestParameters(['_token']);

Telescope::hideRequestHeaders([
'cookie',
'x-csrf-token',
'x-xsrf-token',
]);
}

/**
* Register the Telescope gate.
*
* This gate determines who can access Telescope in non-local environments.
*/
protected function gate(): void
{
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
//
]);
});
}
}
2 changes: 1 addition & 1 deletion bootstrap/providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
return [
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\Filament\AdminPanelServiceProvider::class,
App\Providers\Filament\AdminPanelProvider::class,
App\Providers\HorizonServiceProvider::class,
];
Binary file modified bun.lockb
Binary file not shown.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
"laravel/pulse": "^1.2",
"laravel/sanctum": "^4.0",
"laravel/tinker": "^2.9",
"pxlrbt/filament-environment-indicator": "^2.0",
"sentry/sentry-laravel": "^4.7",
"spatie/laravel-permission": "^6.9",
"stephenjude/filament-debugger": "^3.1",
"tightenco/ziggy": "^2.3"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.13",
"fakerphp/faker": "^1.23",
"laravel/pint": "^1.17",
"laravel/telescope": "^5.2",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.3",
"pestphp/pest": "^3.0",
Expand Down Expand Up @@ -97,7 +100,9 @@
},
"extra": {
"laravel": {
"dont-discover": []
"dont-discover": [
"laravel/telescope"
]
}
},
"config": {
Expand Down
Loading