Skip to content

Commit a58325e

Browse files
committed
add Filament v2 support
1 parent 90870dc commit a58325e

File tree

8 files changed

+47
-58
lines changed

8 files changed

+47
-58
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3-
## 1.0.0 - 201X-XX-XX
3+
## 2.0.0 - 2022-06-18
4+
5+
**Changed**
6+
- Filament v2 support
7+
8+
## 1.0.0 - 2021-08-08
49

510
- Initial release

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/nop-app/filament.svg?style=flat-square)](https://packagist.org/packages/nop-app/filament)
44
[![Total Downloads](https://img.shields.io/packagist/dt/nop-app/filament.svg?style=flat-square)](https://packagist.org/packages/nop-app/filament)
55

6-
Integrate Nop with [Filament](https://filamentadmin.com). The package will enable Nop on all the edit pages of your Filament admin dashboard, e.g. `/admin/resources/projects/<id>/edit`, preventing multiple users to access the same page simultaneously.
6+
Integrate Nop with [Filament](https://filamentadmin.com). The package will enable Nop on all the edit pages of your Filament admin dashboard, e.g. `/admin/projects/<id>/edit`, preventing multiple users to access the same page simultaneously.
77

88
## Installation
99

@@ -13,18 +13,10 @@ Install the package via composer:
1313
composer require nop-app/filament
1414
```
1515

16-
Then publish the package config file and assets as well:
16+
Then publish the package config file:
1717

1818
```bash
1919
php artisan vendor:publish --tag=nop-config
20-
php artisan vendor:publish --tag=nop-assets
21-
```
22-
23-
### Upgrade
24-
When upgrading, you may want to republish the assets:
25-
26-
```bash
27-
php artisan vendor:publish --tag=nop-assets --force
2820
```
2921

3022
## Configuration

composer.json

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,15 @@
1717
}
1818
],
1919
"require": {
20-
"php": "^7.4|^8.0",
21-
"filament/filament": "^1.6",
22-
"illuminate/support": "^8.0",
23-
"spatie/laravel-package-tools": "^1.5"
24-
},
25-
"require-dev": {
26-
"orchestra/testbench": "^6.0",
27-
"phpunit/phpunit": "^9.0"
20+
"php": "^8.0",
21+
"filament/filament": "^2.13",
22+
"illuminate/support": "^9.0"
2823
},
2924
"autoload": {
3025
"psr-4": {
3126
"Nop\\Filament\\": "src"
3227
}
3328
},
34-
"autoload-dev": {
35-
"psr-4": {
36-
"Nop\\Filament\\Tests\\": "tests"
37-
}
38-
},
3929
"scripts": {
4030
"test": "vendor/bin/phpunit",
4131
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

config/nop.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
*/
3535
'enabled_routes' => [
3636
// This route enables all resources of your admin
37-
// E.g. /admin/resources/<resource name>/<id or uuid>/edit
38-
'admin/resources/[a-z-_]+/[0-9a-z-]+/edit',
37+
// E.g. /admin/<resource name>/<id or uuid>/edit
38+
'admin/[a-z-_]+/[0-9a-z-]+/edit',
3939
],
4040

4141

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
},
1616
"scripts": {
1717
"build": "npx mix --production"
18-
}
18+
},
19+
"dependencies": {}
1920
}

resources/dist/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const script = document.createElement('script');
33
script.type = 'text/javascript';
44
script.onload = function () {
5-
Nop.init(window.filamentConfig.nop);
5+
Nop.init(window.filamentData.nop);
66
};
77
script.src = 'https://nop.is/js/sdk.js';
88

src/NopServiceProvider.php

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,52 +2,53 @@
22

33
namespace Nop\Filament;
44

5-
use Filament\Filament;
5+
use Filament\PluginServiceProvider;
6+
use Illuminate\Support\Facades\App;
67
use Illuminate\Support\Facades\Auth;
78
use Illuminate\Support\Facades\Config;
8-
use Spatie\LaravelPackageTools\Package;
9-
use Spatie\LaravelPackageTools\PackageServiceProvider;
109

11-
class NopServiceProvider extends PackageServiceProvider
10+
class NopServiceProvider extends PluginServiceProvider
1211
{
13-
public function configurePackage(Package $package): void
14-
{
15-
$package
16-
->name('nop')
17-
->hasAssets()
18-
->hasConfigFile();
19-
}
12+
public static string $name = 'nop';
2013

21-
public function bootingPackage()
22-
{
23-
Filament::serving(function () {
24-
Filament::registerScript($this->package->name, '/vendor/' . $this->package->name . '/app.js');
14+
protected array $scripts = [
15+
'nop-scripts' => __DIR__ . '/../resources/dist/app.js',
16+
];
2517

26-
$userName = null;
18+
/**
19+
* Provide data to the page scripts.
20+
*
21+
* @return array
22+
*/
23+
protected function getScriptData(): array
24+
{
25+
$userName = null;
2726

28-
if (($userNameField = Config::get('nop.user_name_field')) && Auth::check()) {
29-
$userName = Auth::user()->$userNameField;
30-
}
27+
if (($userNameField = Config::get('nop.user_name_field')) && Auth::check()) {
28+
$userName = Auth::user()->$userNameField;
29+
}
3130

32-
Filament::provideToScript([
33-
'nop' => Config::get('nop.settings') + [
34-
'enabled' => Config::get('nop.enabled', false) && $this->routeEnabled(),
35-
'token' => Config::get('nop.token'),
36-
'user' => $userName,
37-
],
38-
]);
39-
});
31+
return [
32+
'nop' => Config::get('nop.settings') + [
33+
'enabled' => Config::get('nop.enabled', false) && $this->isRouteEnabled(),
34+
'token' => Config::get('nop.token'),
35+
'user' => $userName,
36+
],
37+
];
4038
}
4139

4240
/**
4341
* Check if the current route is enabled.
4442
*
4543
* @return bool
4644
*/
47-
protected function routeEnabled(): bool
45+
protected function isRouteEnabled(): bool
4846
{
47+
/** @var \Illuminate\Http\Request $request */
48+
$request = App::make('request');
49+
4950
foreach (Config::get('nop.enabled_routes') as $pattern) {
50-
if (preg_match('#^' . $pattern . '$#i', request()->path())) {
51+
if (preg_match('#^' . $pattern . '$#i', $request->path())) {
5152
return true;
5253
}
5354
}

0 commit comments

Comments
 (0)