Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Dec 30, 2024
1 parent b54b88f commit 5706303
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
14 changes: 9 additions & 5 deletions resources/views/404.blade.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<div class="flex items-center justify-center min-h-[80vh]"> <!-- Adjust for navbar -->
<div class="flex items-center justify-center min-h-[80vh]">
<div class="text-center">
<h1 class="text-9xl font-black text-center mb-4 relative">
<span class="absolute text-gray-400 transform -rotate-12 -top-8 -left-6 opacity-50">404</span>
<span class="absolute text-gray-400 transform -rotate-12 -top-8 -left-6 opacity-50">
404
</span>
<span class="relative z-10">404</span>
</h1>

<p class="text-sm mb-6">The page you're looking for cannot be found.</p>
<p class="text-sm mb-2">
The page you're looking for cannot be found.
</p>

<p class="text-xs text-gray-500 mb-6">
Current URL: <span class="font-mono">{{ request()->fullUrl() }}</span>
</p>

<div class="flex justify-center gap-4">
<x-filament::button icon="heroicon-s-home" tag="a" color="gray" :href="url()->previous()">
<x-filament::button icon="heroicon-o-arrow-uturn-left" tag="a" color="gray" :href="url()->previous()">
Go back to previous page
</x-filament::button>

<x-filament::button icon="heroicon-s-home" tag="a" color="gray" :href="\Filament\Facades\Filament::getCurrentPanel()->getUrl()">
<x-filament::button icon="heroicon-s-home" tag="a" color="primary" :href="\Filament\Facades\Filament::getCurrentPanel()->getUrl()">
Go back to home
</x-filament::button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Filament\Pages\Page;

class ErrorPage extends Page
class PageNotFoundPage extends Page
{
protected static ?string $slug = 'woops';

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

protected static string $view = 'filament-error-pages::404';
Expand Down
6 changes: 4 additions & 2 deletions src/FilamentErrorPagesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Cmsmaxinc\FilamentErrorPages;

use Cmsmaxinc\FilamentErrorPages\Filament\Pages\ErrorPage;
use Cmsmaxinc\FilamentErrorPages\Filament\Pages\PageNotFoundPage;
use Filament\Contracts\Plugin;
use Filament\Panel;

use function filament;

class FilamentErrorPagesPlugin implements Plugin
{
public function getId(): string
Expand All @@ -16,7 +18,7 @@ public function getId(): string
public function register(Panel $panel): void
{
$panel->pages([
ErrorPage::class,
PageNotFoundPage::class,
]);
}

Expand Down
13 changes: 9 additions & 4 deletions src/FilamentErrorPagesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cmsmaxinc\FilamentErrorPages;

use Illuminate\Contracts\Debug\ExceptionHandler;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down Expand Up @@ -36,22 +37,26 @@ public function configurePackage(Package $package): void
if (file_exists($package->basePath('/../resources/views'))) {
$package->hasViews(static::$viewNamespace);
}

$this->registerCustomErrorHandler();
}

public function packageRegistered(): void {}

public function packageBooted(): void
{
$this->registerCustomErrorHandler();
// $this->registerCustomErrorHandler();
}

protected function registerCustomErrorHandler(): void
{
app('Illuminate\Contracts\Debug\ExceptionHandler')
app(ExceptionHandler::class)
->renderable(function (Throwable $e, $request) {
if ($e instanceof NotFoundHttpException) {
// TODO: Figure out how to redirect to the error page based on the panel, multi tenancy, etc.
return redirect('admin/error-page');
// TODO: Figure out how to get the current panel ID and user
// dd(auth()->user(), filament()->getCurrentPanel());

return redirect('admin/woops'); // redirect to correct page....
}

return null;
Expand Down

0 comments on commit 5706303

Please sign in to comment.