├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── bin └── build.js ├── composer.json ├── postcss.config.cjs ├── resources ├── css │ └── index.css ├── dist │ └── .gitkeep ├── js │ └── index.js ├── lang │ └── en │ │ └── pdf-viewer.php └── views │ ├── .gitkeep │ └── filament │ └── components │ ├── forms │ └── pdf-viewer-field.blade.php │ └── infolists │ └── pdf-viewer-entry.blade.php └── src ├── Commands └── FilamentPdfViewerCommand.php ├── Facades └── FilamentPdfViewer.php ├── FilamentPdfViewer.php ├── FilamentPdfViewerPlugin.php ├── FilamentPdfViewerServiceProvider.php ├── Forms └── Components │ └── PdfViewerField.php ├── Infolists └── Components │ └── PdfViewerEntry.php └── Testing └── TestsFilamentPdfViewer.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `filament-pdf-viewer` will be documented in this file. 4 | 5 | ## v1.0.7 - 2025-02-07 6 | 7 | ### What's Changed 8 | 9 | * Bump dependabot/fetch-metadata from 2.2.0 to 2.3.0 by @dependabot in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/15 10 | * Fix #12 : fix wrong return type by @CharlieEtienne in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/18 11 | 12 | ### New Contributors 13 | 14 | * @CharlieEtienne made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/18 15 | 16 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/compare/v1.0.6...v1.0.7 17 | 18 | ## v1.0.6 - 2024-09-26 19 | 20 | ### What's Changed 21 | 22 | * Update PdfViewerEntry.php by @kmoconnect in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/9 23 | 24 | ### New Contributors 25 | 26 | * @kmoconnect made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/9 27 | 28 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/compare/v1.0.5...v1.0.6 29 | 30 | ## v1.0.5 - 2024-09-05 31 | 32 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/compare/v1.0.4...v1.0.5 33 | 34 | ## v1.0.4 - 2024-09-05 35 | 36 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/compare/v1.0.3...v1.0.4 37 | 38 | ## v1.0.3 - 2024-09-05 39 | 40 | ### What's Changed 41 | 42 | * Improve file url handler by @a21ns1g4ts in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/8 43 | 44 | ### New Contributors 45 | 46 | * @a21ns1g4ts made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/8 47 | 48 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/compare/v1.0.2...v1.0.3 49 | 50 | ## v1.0.2 - 2024-07-11 51 | 52 | ### What's Changed 53 | 54 | * Bump dependabot/fetch-metadata from 2.1.0 to 2.2.0 by @dependabot in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/6 55 | * Allow closure in setting the file url in infolists entry. by @SalehHub in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/5 56 | 57 | ### New Contributors 58 | 59 | * @SalehHub made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/5 60 | 61 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/compare/v1.0.1...v1.0.2 62 | 63 | ## v1.0.1 - 2024-07-05 64 | 65 | ### What's Changed 66 | 67 | * Update README.md by @jeffersonsimaogoncalves in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/3 68 | * Allow closure in setting the file url in form field. by @agcodex01 in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/4 69 | 70 | ### New Contributors 71 | 72 | * @jeffersonsimaogoncalves made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/3 73 | * @agcodex01 made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/4 74 | 75 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/compare/v1.0.0...v1.0.1 76 | 77 | ## v1.0.0 - 2024-06-22 78 | 79 | ### What's Changed 80 | 81 | * Bump dependabot/fetch-metadata from 1.6.0 to 2.1.0 by @dependabot in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/1 82 | * Develop by @rmsramos in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/2 83 | 84 | ### New Contributors 85 | 86 | * @dependabot made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/1 87 | * @rmsramos made their first contribution in https://github.com/joaopaulolndev/filament-pdf-viewer/pull/2 88 | 89 | **Full Changelog**: https://github.com/joaopaulolndev/filament-pdf-viewer/commits/v1.0.0 90 | 91 | ## 1.0.0 - 202X-XX-XX 92 | 93 | - initial release 94 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) joaopaulolndev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Filament package to show pdf document viewer 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/joaopaulolndev/filament-pdf-viewer.svg?style=flat-square)](https://packagist.org/packages/joaopaulolndev/filament-pdf-viewer) 4 | [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/joaopaulolndev/filament-pdf-viewer/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/joaopaulolndev/filament-pdf-viewer/actions?query=workflow%3Arun-tests+branch%3Amain) 5 | [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/joaopaulolndev/filament-pdf-viewer/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/joaopaulolndev/filament-pdf-viewer/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain) 6 | [![Total Downloads](https://img.shields.io/packagist/dt/joaopaulolndev/filament-pdf-viewer.svg?style=flat-square)](https://packagist.org/packages/joaopaulolndev/filament-pdf-viewer) 7 | 8 | FilamentPHP package to show pdf documents with records saved in the database or show documents without a database in the form of your resource. 9 |
10 | 11 | ![Screenshot of Application Feature](https://raw.githubusercontent.com/joaopaulolndev/filament-pdf-viewer/main/art/joaopaulolndev-filament-pdf-viewer.jpg) 12 | 13 |
14 | 15 | ## Features & Screenshots 16 | 17 | - **Form Field:** Show a pdf document viewer in a form field. 18 | - **Infolist Entry:** Show a pdf document viewer in a infolist entry. 19 | - **Support**: [Laravel 11](https://laravel.com) and [Filament 3.x](https://filamentphp.com) 20 | 21 | ## Installation 22 | 23 | You can install the package via composer: 24 | 25 | ```bash 26 | composer require joaopaulolndev/filament-pdf-viewer 27 | ``` 28 | 29 | Optionally, you can publish the views using 30 | 31 | ```bash 32 | php artisan vendor:publish --tag="filament-pdf-viewer-views" 33 | ``` 34 | 35 | ## Usage in form field 36 | 37 | ```php 38 | use Joaopaulolndev\FilamentPdfViewer\Forms\Components\PdfViewerField; 39 | 40 | public static function form(Form $form): Form 41 | { 42 | return $form 43 | ->schema([ 44 | PdfViewerField::make('file') 45 | ->label('View the PDF') 46 | ->minHeight('40svh') 47 | ]); 48 | } 49 | ``` 50 | 51 | ## Usage in infolist entry 52 | 53 | ```php 54 | use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry; 55 | 56 | public static function infolist(Infolist $infolist): Infolist 57 | { 58 | return $infolist 59 | ->schema([ 60 | PdfViewerEntry::make('file') 61 | ->label('View the PDF') 62 | ->minHeight('40svh') 63 | ]); 64 | } 65 | ``` 66 | 67 | Optionally, you can use anothe methods to set the pdf viewer 68 | 69 | ```php 70 | use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry; 71 | 72 | public static function infolist(Infolist $infolist): Infolist 73 | { 74 | return $infolist 75 | ->schema([ 76 | PdfViewerEntry::make('file') 77 | ->label('View the PDF') 78 | ->minHeight('40svh') 79 | ->fileUrl(Storage::url('dummy.pdf')) // Set the file url if you are getting a pdf without database 80 | ->columnSpanFull() 81 | ]); 82 | } 83 | ``` 84 | 85 | Optionally, you can use section to set the pdf viewer 86 | 87 | ```php 88 | use Joaopaulolndev\FilamentPdfViewer\Infolists\Components\PdfViewerEntry; 89 | 90 | public static function infolist(Infolist $infolist): Infolist 91 | { 92 | return $infolist 93 | ->schema([ 94 | \Filament\Infolists\Components\Section::make('PDF Viewer') 95 | ->description('Prevent the PDF from being downloaded') 96 | ->collapsible() 97 | ->schema([ 98 | PdfViewerEntry::make('file') 99 | ->label('View the PDF') 100 | ->minHeight('40svh') 101 | ->fileUrl(Storage::url('dummy.pdf')) // Set the file url if you are getting a pdf without database 102 | ->columnSpanFull() 103 | ]); 104 | ]); 105 | } 106 | ``` 107 | 108 | ## Testing 109 | 110 | ```bash 111 | composer test 112 | ``` 113 | 114 | ## Changelog 115 | 116 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 117 | 118 | ## Contributing 119 | 120 | Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. 121 | 122 | ## Security Vulnerabilities 123 | 124 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. 125 | 126 | ## Credits 127 | 128 | - [João Paulo Leite Nascimento](https://github.com/joaopaulolndev) 129 | - [Rômulo Ramos](https://github.com/rmsramos) 130 | - [All Contributors](../../contributors) 131 | 132 | ## License 133 | 134 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 135 | -------------------------------------------------------------------------------- /bin/build.js: -------------------------------------------------------------------------------- 1 | import esbuild from 'esbuild' 2 | 3 | const isDev = process.argv.includes('--dev') 4 | 5 | async function compile(options) { 6 | const context = await esbuild.context(options) 7 | 8 | if (isDev) { 9 | await context.watch() 10 | } else { 11 | await context.rebuild() 12 | await context.dispose() 13 | } 14 | } 15 | 16 | const defaultOptions = { 17 | define: { 18 | 'process.env.NODE_ENV': isDev ? `'development'` : `'production'`, 19 | }, 20 | bundle: true, 21 | mainFields: ['module', 'main'], 22 | platform: 'neutral', 23 | sourcemap: isDev ? 'inline' : false, 24 | sourcesContent: isDev, 25 | treeShaking: true, 26 | target: ['es2020'], 27 | minify: !isDev, 28 | plugins: [{ 29 | name: 'watchPlugin', 30 | setup: function (build) { 31 | build.onStart(() => { 32 | console.log(`Build started at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`) 33 | }) 34 | 35 | build.onEnd((result) => { 36 | if (result.errors.length > 0) { 37 | console.log(`Build failed at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`, result.errors) 38 | } else { 39 | console.log(`Build finished at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`) 40 | } 41 | }) 42 | } 43 | }], 44 | } 45 | 46 | compile({ 47 | ...defaultOptions, 48 | entryPoints: ['./resources/js/index.js'], 49 | outfile: './resources/dist/filament-pdf-viewer.js', 50 | }) 51 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "joaopaulolndev/filament-pdf-viewer", 3 | "description": "Filament package to show pdf document viewer", 4 | "keywords": [ 5 | "joaopaulolndev", 6 | "laravel", 7 | "filament-pdf-viewer" 8 | ], 9 | "homepage": "https://github.com/joaopaulolndev/filament-pdf-viewer", 10 | "support": { 11 | "issues": "https://github.com/joaopaulolndev/filament-pdf-viewer/issues", 12 | "source": "https://github.com/joaopaulolndev/filament-pdf-viewer" 13 | }, 14 | "license": "MIT", 15 | "authors": [ 16 | { 17 | "name": "João Paulo Leite Nascimento", 18 | "email": "joaopauloln7@gmail.com", 19 | "role": "Developer" 20 | } 21 | ], 22 | "require": { 23 | "php": "^8.1", 24 | "filament/filament": "^3.0", 25 | "spatie/laravel-package-tools": "^1.15.0" 26 | }, 27 | "require-dev": { 28 | "nunomaduro/collision": "^7.9", 29 | "orchestra/testbench": "^8.0", 30 | "pestphp/pest": "^2.1", 31 | "pestphp/pest-plugin-arch": "^2.0", 32 | "pestphp/pest-plugin-laravel": "^2.0" 33 | }, 34 | "autoload": { 35 | "psr-4": { 36 | "Joaopaulolndev\\FilamentPdfViewer\\": "src/", 37 | "Joaopaulolndev\\FilamentPdfViewer\\Database\\Factories\\": "database/factories/" 38 | } 39 | }, 40 | "autoload-dev": { 41 | "psr-4": { 42 | "Joaopaulolndev\\FilamentPdfViewer\\Tests\\": "tests/" 43 | } 44 | }, 45 | "scripts": { 46 | "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", 47 | "test": "vendor/bin/pest", 48 | "test-coverage": "vendor/bin/pest --coverage" 49 | }, 50 | "config": { 51 | "sort-packages": true, 52 | "allow-plugins": { 53 | "pestphp/pest-plugin": true, 54 | "phpstan/extension-installer": true 55 | } 56 | }, 57 | "extra": { 58 | "laravel": { 59 | "providers": [ 60 | "Joaopaulolndev\\FilamentPdfViewer\\FilamentPdfViewerServiceProvider" 61 | ], 62 | "aliases": { 63 | "FilamentPdfViewer": "Joaopaulolndev\\FilamentPdfViewer\\Facades\\FilamentPdfViewer" 64 | } 65 | } 66 | }, 67 | "minimum-stability": "dev", 68 | "prefer-stable": true 69 | } -------------------------------------------------------------------------------- /postcss.config.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | "postcss-import": {}, 4 | "tailwindcss/nesting": {}, 5 | tailwindcss: {}, 6 | autoprefixer: {}, 7 | }, 8 | } 9 | -------------------------------------------------------------------------------- /resources/css/index.css: -------------------------------------------------------------------------------- 1 | @import '../../vendor/filament/filament/resources/css/theme.css'; 2 | -------------------------------------------------------------------------------- /resources/dist/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joaopaulolndev/filament-pdf-viewer/712e39e0a57475c5a7ab1dd8ecf10ce0f5079728/resources/dist/.gitkeep -------------------------------------------------------------------------------- /resources/js/index.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joaopaulolndev/filament-pdf-viewer/712e39e0a57475c5a7ab1dd8ecf10ce0f5079728/resources/js/index.js -------------------------------------------------------------------------------- /resources/lang/en/pdf-viewer.php: -------------------------------------------------------------------------------- 1 | 13 | $hasInlineLabel, 17 | ]) 18 | > 19 | {{ $getLabel() }} 20 | 21 | 22 | 28 | @if(!empty($getState())) 29 | 33 | @elseif(!empty($getFileUrl())) 34 | 38 | @endif 39 | 40 | 41 | -------------------------------------------------------------------------------- /resources/views/filament/components/infolists/pdf-viewer-entry.blade.php: -------------------------------------------------------------------------------- 1 | 2 | @if(!empty($getState())) 3 | 7 | @elseif(!empty($getFileUrl())) 8 | 12 | @endif 13 | 14 | -------------------------------------------------------------------------------- /src/Commands/FilamentPdfViewerCommand.php: -------------------------------------------------------------------------------- 1 | comment('All done'); 16 | 17 | return self::SUCCESS; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Facades/FilamentPdfViewer.php: -------------------------------------------------------------------------------- 1 | getId()); 34 | 35 | return $plugin; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/FilamentPdfViewerServiceProvider.php: -------------------------------------------------------------------------------- 1 | name(static::$name) 26 | ->hasCommands($this->getCommands()) 27 | ->hasInstallCommand(function (InstallCommand $command) { 28 | $command 29 | ->publishConfigFile() 30 | ->askToRunMigrations() 31 | ->askToStarRepoOnGitHub('joaopaulolndev/filament-pdf-viewer'); 32 | }); 33 | 34 | $configFileName = $package->shortName(); 35 | 36 | if (file_exists($package->basePath("/../config/{$configFileName}.php"))) { 37 | $package->hasConfigFile(); 38 | } 39 | 40 | if (file_exists($package->basePath('/../resources/lang'))) { 41 | $package->hasTranslations(); 42 | } 43 | 44 | if (file_exists($package->basePath('/../resources/views'))) { 45 | $package->hasViews(static::$viewNamespace); 46 | } 47 | } 48 | 49 | public function packageRegistered(): void 50 | { 51 | } 52 | 53 | public function packageBooted(): void 54 | { 55 | // Testing 56 | Testable::mixin(new TestsFilamentPdfViewer()); 57 | } 58 | 59 | protected function getAssetPackageName(): ?string 60 | { 61 | return 'joaopaulolndev/filament-pdf-viewer'; 62 | } 63 | 64 | /** 65 | * @return array 66 | */ 67 | protected function getCommands(): array 68 | { 69 | return [ 70 | FilamentPdfViewerCommand::class, 71 | ]; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/Forms/Components/PdfViewerField.php: -------------------------------------------------------------------------------- 1 | hidden(fn (string $context): bool => $context === 'create'); 32 | } 33 | 34 | public function minHeight(string $minHeight): self 35 | { 36 | $this->minHeight = $minHeight; 37 | 38 | return $this; 39 | } 40 | 41 | public function getMinHeight(): string 42 | { 43 | return $this->minHeight; 44 | } 45 | 46 | public function fileUrl(string|Closure $fileUrl): self 47 | { 48 | $this->fileUrl = $fileUrl; 49 | 50 | return $this; 51 | } 52 | 53 | public function visibility(string|Closure $visibility): static 54 | { 55 | $this->visibility = $visibility; 56 | 57 | return $this; 58 | } 59 | 60 | public function getDisk(): Filesystem 61 | { 62 | return Storage::disk($this->getDiskName()); 63 | } 64 | 65 | public function getDiskName(): string 66 | { 67 | return $this->evaluate($this->disk) ?? config('filament.default_filesystem_disk'); 68 | } 69 | 70 | public function getFileUrl(?string $state = null): ?string 71 | { 72 | if (empty($state)) { 73 | return $this->evaluate($this->fileUrl); 74 | } 75 | 76 | if ((filter_var($state, FILTER_VALIDATE_URL) !== false) || str($state)->startsWith('data:')) { 77 | return $state; 78 | } 79 | 80 | /** @var FilesystemAdapter $storage */ 81 | $storage = $this->getDisk(); 82 | 83 | if ($this->shouldCheckFileExistence()) { 84 | try { 85 | if (! $storage->exists($state)) { 86 | return null; 87 | } 88 | } catch (UnableToCheckFileExistence $exception) { 89 | return null; 90 | } 91 | } 92 | 93 | if ($this->getVisibility() === 'private') { 94 | try { 95 | return $storage->temporaryUrl( 96 | $state, 97 | now()->addMinutes(60), 98 | ); 99 | } catch (Throwable $exception) { 100 | // This driver does not support creating temporary URLs. 101 | } 102 | } 103 | 104 | return $storage->url($state); 105 | } 106 | 107 | public function getVisibility(): string 108 | { 109 | return $this->evaluate($this->visibility); 110 | } 111 | 112 | public function checkFileExistence(bool|Closure $condition = true): static 113 | { 114 | $this->shouldCheckFileExistence = $condition; 115 | 116 | return $this; 117 | } 118 | 119 | public function shouldCheckFileExistence(): bool 120 | { 121 | return (bool) $this->evaluate($this->shouldCheckFileExistence); 122 | } 123 | 124 | /** 125 | * @return null|string|void 126 | */ 127 | public function getRoute(string $file) 128 | { 129 | return $this->getFileUrl($file); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /src/Infolists/Components/PdfViewerEntry.php: -------------------------------------------------------------------------------- 1 | minHeight = $minHeight; 30 | 31 | return $this; 32 | } 33 | 34 | public function getMinHeight(): string 35 | { 36 | return $this->minHeight; 37 | } 38 | 39 | public function getDisk(): Filesystem 40 | { 41 | return Storage::disk($this->getDiskName()); 42 | } 43 | 44 | public function getDiskName(): string 45 | { 46 | return $this->evaluate($this->disk) ?? config('filament.default_filesystem_disk'); 47 | } 48 | 49 | public function fileUrl(string|Closure $fileUrl): self 50 | { 51 | $this->fileUrl = $fileUrl; 52 | 53 | return $this; 54 | } 55 | 56 | public function getFileUrl(?string $state = null): string|null 57 | { 58 | if (empty($state)) { 59 | return $this->evaluate($this->fileUrl); 60 | } 61 | 62 | if ((filter_var($state, FILTER_VALIDATE_URL) !== false) || str($state)->startsWith('data:')) { 63 | return $state; 64 | } 65 | 66 | /** @var FilesystemAdapter $storage */ 67 | $storage = $this->getDisk(); 68 | 69 | if ($this->shouldCheckFileExistence()) { 70 | try { 71 | if (! $storage->exists($state)) { 72 | return null; 73 | } 74 | } catch (UnableToCheckFileExistence $exception) { 75 | return null; 76 | } 77 | } 78 | 79 | if ($this->getVisibility() === 'private') { 80 | try { 81 | return $storage->temporaryUrl( 82 | $state, 83 | now()->addMinutes(60), 84 | ); 85 | } catch (Throwable $exception) { 86 | // This driver does not support creating temporary URLs. 87 | } 88 | } 89 | 90 | return $storage->url($state); 91 | } 92 | 93 | // public function getFileUrl(): string 94 | // { 95 | // return $this->evaluate($this->fileUrl); 96 | // } 97 | 98 | public function getVisibility(): string 99 | { 100 | return $this->evaluate($this->visibility); 101 | } 102 | 103 | public function checkFileExistence(bool|Closure $condition = true): static 104 | { 105 | $this->shouldCheckFileExistence = $condition; 106 | 107 | return $this; 108 | } 109 | 110 | public function shouldCheckFileExistence(): bool 111 | { 112 | return (bool) $this->evaluate($this->shouldCheckFileExistence); 113 | } 114 | 115 | /** 116 | * @return null|string|void 117 | */ 118 | public function getRoute(string $file) 119 | { 120 | return $this->getFileUrl($file); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/Testing/TestsFilamentPdfViewer.php: -------------------------------------------------------------------------------- 1 |