Skip to content

Commit 271556e

Browse files
committed
Update docs, add translations and helpers
1 parent d2d91b9 commit 271556e

File tree

8 files changed

+57
-8
lines changed

8 files changed

+57
-8
lines changed

composer.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"spatie/laravel-package-tools": "^1.12"
1717
},
1818
"require-dev": {
19+
"larastan/larastan": "^2.0",
1920
"laravel/pint": "^1.0",
2021
"nunomaduro/collision": "^7.0 || ^8.0",
21-
"nunomaduro/larastan": "^2.0",
2222
"orchestra/testbench": "^8.0 || ^9.0",
2323
"pestphp/pest": "^2.0",
2424
"pestphp/pest-plugin-laravel": "^2.0",
@@ -30,7 +30,10 @@
3030
"psr-4": {
3131
"Wotz\\FilamentLivePreview\\": "src",
3232
"Wotz\\FilamentLivePreview\\Database\\Factories\\": "database/factories"
33-
}
33+
},
34+
"files": [
35+
"src/helpers.php"
36+
]
3437
},
3538
"autoload-dev": {
3639
"psr-4": {

docs/index.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ php artisan vendor:publish --tag="filament-live-preview-views"
3838

3939
Follow the Laravel Reverb installation instructions [here](https://laravel.com/docs/12.x/reverb)
4040

41-
#### Fix Livewire and Reverb
41+
#### Fix Livewire and Websockets
4242

4343
In `bootstrap/app.php`, add the following lines:
4444

@@ -199,3 +199,19 @@ In `routes/channels.php`, add the following line:
199199
```php
200200
Broadcast::channel('live-preview', function () {});
201201
```
202+
203+
#### Blade files
204+
205+
If you load a blade file which loads a Livewire component, it wil break the live preview for some unknown reason.
206+
207+
This can be fixed by wrapping the Livewire component in a conditional, like this:
208+
209+
```blade
210+
@if (! is_live_preview_request())
211+
<livewire:filters />
212+
@else
213+
{{ __('filament-live-preview::alert.preview unavailable for :name', [
214+
'name' => "filters"
215+
]) }}
216+
@endif
217+
```

phpstan.neon.dist

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 4
5+
level: 5
66
paths:
77
- src
88
- config
9-
- database
109
tmpDir: build/phpstan
1110
checkOctaneCompatibility: true
1211
checkModelProperties: true
13-
checkMissingIterableValueType: false
14-

resources/lang/en/alert.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'preview unavailable for :name' => 'Preview unavailable for :name',
5+
];

resources/lang/nl/alert.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
'preview unavailable for :name' => 'Preview onbeschikbaar voor :name',
5+
];

src/Livewire/LivePreviewScreen.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ class LivePreviewScreen extends Component
1515

1616
public function mount()
1717
{
18-
abort_unless($this->token = request()->query('token'), 404);
18+
$this->token = request()->query('token');
19+
20+
abort_unless(filled($this->token), 404);
1921

2022
$this->refreshPreview();
2123
}

src/Providers/FilamentLivePreviewServiceProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public function configurePackage(Package $package): void
1313
->name('filament-live-preview')
1414
->setBasePath(__DIR__ . '/../')
1515
->hasConfigFile()
16+
->hasTranslations()
1617
->hasRoute('web')
1718
->hasViews();
1819
}

src/helpers.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
if (! function_exists('is_live_preview_request')) {
4+
function is_live_preview_request(): bool
5+
{
6+
if (request()->routeIs('live-preview-frame')) {
7+
return true;
8+
}
9+
10+
if (app('livewire')->isLivewireRequest()) {
11+
$snapshot = json_decode(request('components.0.snapshot'), true);
12+
13+
if (($snapshot['memo']['name'] ?? '') === 'filament-live-preview::live-preview-screen') {
14+
return true;
15+
}
16+
}
17+
18+
return false;
19+
}
20+
}

0 commit comments

Comments
 (0)