Compare commits
537 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6556cf017a | ||
|
|
514c010804 | ||
|
|
b3a5624ad4 | ||
|
|
3857aa33d2 | ||
|
|
c625a5c967 | ||
|
|
b4d35adfb4 | ||
|
|
0c1d970a9c | ||
|
|
3df600bcda | ||
|
|
c9e0bb3bda | ||
|
|
3aae5068ce | ||
|
|
255353763f | ||
|
|
99a49848ca | ||
|
|
def9e3c722 | ||
|
|
6cc46cf652 | ||
|
|
9ac72ffda8 | ||
|
|
3f1bdb1d8e | ||
|
|
f3d2b0c71f | ||
|
|
4071ba6d49 | ||
|
|
4ec50d7ca1 | ||
|
|
51b7f28634 | ||
|
|
7f6b59cd4f | ||
|
|
80b4428b72 | ||
|
|
010ecd63ac | ||
|
|
741104de05 | ||
|
|
5254ca3ebe | ||
|
|
aefbb5be33 | ||
|
|
d22bb52f35 | ||
|
|
088d951bea | ||
|
|
01fe642a9d | ||
|
|
258e7127f7 | ||
|
|
7e44db0e56 | ||
|
|
e1c07d84df | ||
|
|
145a4af407 | ||
|
|
d1a7b6002a | ||
|
|
a9c0bdee34 | ||
|
|
604b535895 | ||
|
|
c67546b949 | ||
|
|
0a45a1c8b2 | ||
|
|
3cd83ad69c | ||
|
|
d27df25b3c | ||
|
|
e55e984f98 | ||
|
|
5fbc0e0a37 | ||
|
|
3313786480 | ||
|
|
5ed532535b | ||
|
|
a8361f7b22 | ||
|
|
a190ccf8dc | ||
|
|
3f927f9ec1 | ||
|
|
33692960ff | ||
|
|
1f79a4e790 | ||
|
|
903e1cccc6 | ||
|
|
3f7f6206bd | ||
|
|
be00824f59 | ||
|
|
eb4220adc9 | ||
|
|
3562a60461 | ||
|
|
4d80f26519 | ||
|
|
29dc893806 | ||
|
|
35abe4cfd7 | ||
|
|
275b359b53 | ||
|
|
0be4f4cd94 | ||
|
|
2ffd09877e | ||
|
|
a5d2445e3f | ||
|
|
92631cdee9 | ||
|
|
0f63b8153a | ||
|
|
b6983d5377 | ||
|
|
78899bef61 | ||
|
|
9397651515 | ||
|
|
f692fb681a | ||
|
|
6de17d3e3c | ||
|
|
b2b24db2e6 | ||
|
|
2af546643e | ||
|
|
e63b13e5fd | ||
|
|
36385c2242 | ||
|
|
ed67a44f5f | ||
|
|
fb8b2fa935 | ||
|
|
6e1b7613e4 | ||
|
|
175b104ebc | ||
|
|
a72a2466ef | ||
|
|
9952e2226d | ||
|
|
5fa9c334ee | ||
|
|
d1f50c8dd9 | ||
|
|
557cff5e05 | ||
|
|
fd1d31d347 | ||
|
|
71d5521ca8 | ||
|
|
489d39099f | ||
|
|
cbd6a227ee | ||
|
|
b3d2b2ec7a | ||
|
|
2889e46685 | ||
|
|
761878e1b6 | ||
|
|
4169b07b39 | ||
|
|
8c001cf984 | ||
|
|
a73adb9acf | ||
|
|
6ed9867f6b | ||
|
|
b1667ff445 | ||
|
|
db4a25fb5c | ||
|
|
ee21924253 | ||
|
|
37ea8aa6b0 | ||
|
|
d4c495eaee | ||
|
|
434046cd3e | ||
|
|
eee61494d0 | ||
|
|
053864a589 | ||
|
|
dc87d0d415 | ||
|
|
ae1b41e068 | ||
|
|
277aae4bca | ||
|
|
f727c4cddb | ||
|
|
58c91fe7bc | ||
|
|
cc29f729d3 | ||
|
|
ff8982c2ee | ||
|
|
aab1e86eee | ||
|
|
3388b4fdec | ||
|
|
8ef6e2b64c | ||
|
|
dd5c074976 | ||
|
|
9861ff3a9b | ||
|
|
b4607d8e01 | ||
|
|
7a98295853 | ||
|
|
95e7682cc2 | ||
|
|
251c29b4bd | ||
|
|
96587db6a2 | ||
|
|
06aecba93d | ||
|
|
bcadd716fe | ||
|
|
b2e1ee9e24 | ||
|
|
e3612ebf23 | ||
|
|
25d5a9617d | ||
|
|
b6e25806ea | ||
|
|
f0a8e5e318 | ||
|
|
c5dbfa2c4b | ||
|
|
93273b5a45 | ||
|
|
751449de5e | ||
|
|
e601222b4f | ||
|
|
30685c4595 | ||
|
|
60c951a1f8 | ||
|
|
ccc09f0967 | ||
|
|
de9834d6a7 | ||
|
|
09dd3db506 | ||
|
|
560100e592 | ||
|
|
0f5ef71936 | ||
|
|
84b2f36440 | ||
|
|
92c605d9df | ||
|
|
0fddf4f348 | ||
|
|
ef64bdd7b3 | ||
|
|
465b2a524b | ||
|
|
f2c47ba2f3 | ||
|
|
eab8c45f57 | ||
|
|
2215e12717 | ||
|
|
f76e5b4d7b | ||
|
|
9d1b12b0a3 | ||
|
|
d89482c4aa | ||
|
|
488808a7a2 | ||
|
|
8e788dfd8e | ||
|
|
200d2bc44d | ||
|
|
f9424781c0 | ||
|
|
f2441990cd | ||
|
|
369d205d6a | ||
|
|
b63d4e753b | ||
|
|
fbe7641cb7 | ||
|
|
1ebcf75806 | ||
|
|
88b324b47a | ||
|
|
50768d5648 | ||
|
|
7cfe8d64c4 | ||
|
|
f6f5385751 | ||
|
|
62084f590e | ||
|
|
c7edf262f6 | ||
|
|
4294377160 | ||
|
|
1ae9519594 | ||
|
|
c0f7d572cb | ||
|
|
247fd27368 | ||
|
|
39e5d20444 | ||
|
|
8900e5088a | ||
|
|
e52cc6205a | ||
|
|
a85be2d666 | ||
|
|
bffaadec1b | ||
|
|
0c7398c7ac | ||
|
|
a44ce140fc | ||
|
|
8afe483cee | ||
|
|
9bd3107303 | ||
|
|
5b124cc433 | ||
|
|
661426668e | ||
|
|
2df37131d1 | ||
|
|
c55b2f1f85 | ||
|
|
705739d2d3 | ||
|
|
35bf27097a | ||
|
|
59d60a5b03 | ||
|
|
0cd7c7e4f6 | ||
|
|
254dbaf2ec | ||
|
|
705104524e | ||
|
|
a7da48a5dd | ||
|
|
df87d541cd | ||
|
|
07ba298c5e | ||
|
|
1ce6e8cace | ||
|
|
57f783490b | ||
|
|
eaab262629 | ||
|
|
e2e05f9cbf | ||
|
|
24ce8bc60d | ||
|
|
75592aaeb2 | ||
|
|
c11ad19220 | ||
|
|
db799a7d6a | ||
|
|
7fea371857 | ||
|
|
d7b3899e71 | ||
|
|
e2886fb67e | ||
|
|
8936e4c2d5 | ||
|
|
92bb321a68 | ||
|
|
57c8997dd0 | ||
|
|
2df031a60f | ||
|
|
77384a1abe | ||
|
|
7b20082537 | ||
|
|
3531e4b296 | ||
|
|
4e92501985 | ||
|
|
d7632d8289 | ||
|
|
f404b3e9c6 | ||
|
|
730f9b7451 | ||
|
|
2fe5fd70c9 | ||
|
|
6afe8738df | ||
|
|
761a940abd | ||
|
|
f87c1dd5ee | ||
|
|
de70310c90 | ||
|
|
11f9b1ed48 | ||
|
|
060a6b72a7 | ||
|
|
70cc81f110 | ||
|
|
bcc1a9b9a8 | ||
|
|
1c601a6efd | ||
|
|
fee31d03a7 | ||
|
|
b09dc1ba9d | ||
|
|
dae15c620b | ||
|
|
996a048a76 | ||
|
|
8c20f23dfd | ||
|
|
c80818df4c | ||
|
|
d5e77ae31f | ||
|
|
a14d2c44a1 | ||
|
|
3048747ed6 | ||
|
|
20bf6c4784 | ||
|
|
9b02be5be1 | ||
|
|
d141503b6f | ||
|
|
6a8e4e8edf | ||
|
|
89bbf44b3b | ||
|
|
db1f40bf6f | ||
|
|
5933a06dd3 | ||
|
|
3c510906ee | ||
|
|
b43f4cf292 | ||
|
|
9cc046eeed | ||
|
|
8291ac6714 | ||
|
|
c578ee70c0 | ||
|
|
90501e37fd | ||
|
|
ec45b0dac0 | ||
|
|
34b838c259 | ||
|
|
28ffc8e240 | ||
|
|
c9179fbf90 | ||
|
|
fe5268971a | ||
|
|
8c246e2dba | ||
|
|
81fcfac803 | ||
|
|
ff22b96a8d | ||
|
|
4a2faf0bce | ||
|
|
5c39d07bf5 | ||
|
|
9870aec79f | ||
|
|
833a03e992 | ||
|
|
e074ab5be4 | ||
|
|
b5963693e6 | ||
|
|
1b7ea67fde | ||
|
|
d4f2b9839e | ||
|
|
817f6a175c | ||
|
|
b3619e5941 | ||
|
|
33784410e5 | ||
|
|
6ecf7904fe | ||
|
|
21986f2394 | ||
|
|
4d8212e56f | ||
|
|
865f2958cf | ||
|
|
17890d13ad | ||
|
|
2d33455731 | ||
|
|
49481f9b6a | ||
|
|
7bb800cc0a | ||
|
|
1b8c2c764f | ||
|
|
cb1a1c4c06 | ||
|
|
ddd80a8687 | ||
|
|
010d4569c2 | ||
|
|
62ae0f8299 | ||
|
|
2a3d9cabd0 | ||
|
|
e2a58cf2df | ||
|
|
0fd6db251b | ||
|
|
94d50c11ef | ||
|
|
14c6faafa2 | ||
|
|
ea21076eda | ||
|
|
d378323602 | ||
|
|
f074dee990 | ||
|
|
7bd2917ec4 | ||
|
|
823a39ffa2 | ||
|
|
6953a8d2b2 | ||
|
|
fb40b450b6 | ||
|
|
a28c053945 | ||
|
|
ea0c4ed66d | ||
|
|
7a0716959a | ||
|
|
da322d7b1e | ||
|
|
bbff8a5403 | ||
|
|
c1ad600042 | ||
|
|
5fc32759fd | ||
|
|
59cfd8d71b | ||
|
|
51d5b89df7 | ||
|
|
7c0dcbeb88 | ||
|
|
b4467f8d5b | ||
|
|
363f4ed801 | ||
|
|
1b6b950fb5 | ||
|
|
90988f1538 | ||
|
|
139ba793d0 | ||
|
|
c505dd0924 | ||
|
|
ca5ee33978 | ||
|
|
c2fd5e3fa9 | ||
|
|
b04176ce48 | ||
|
|
5136a4b9f8 | ||
|
|
dcee703aa1 | ||
|
|
7c504339d9 | ||
|
|
5ea0761fe9 | ||
|
|
c9125c3be8 | ||
|
|
84503c19db | ||
|
|
cfd9eba5d7 | ||
|
|
10689d3d12 | ||
|
|
e190fb7805 | ||
|
|
c1351f7d28 | ||
|
|
01f5469e86 | ||
|
|
8c5c86eb6a | ||
|
|
995ada46aa | ||
|
|
2e79381872 | ||
|
|
d1c7b9a418 | ||
|
|
34da2f563d | ||
|
|
5cf77fde1c | ||
|
|
aabf6f27ac | ||
|
|
fbcaee3bdc | ||
|
|
3082c10cdb | ||
|
|
a4d90f0017 | ||
|
|
8adfc9837e | ||
|
|
aa20c8a42b | ||
|
|
0f100d6159 | ||
|
|
7c896243a5 | ||
|
|
954fef7c3e | ||
|
|
105126e498 | ||
|
|
7aa5a8949d | ||
|
|
27079928a7 | ||
|
|
99968e57ec | ||
|
|
f75bc1a551 | ||
|
|
ef347f9381 | ||
|
|
f1aace3d8f | ||
|
|
b2bec62766 | ||
|
|
3a8682bbed | ||
|
|
5cfc1f97fe | ||
|
|
cfc8220f8e | ||
|
|
ac5ffefaed | ||
|
|
cbd2b8e0e9 | ||
|
|
f0f427a7bb | ||
|
|
7b6f651015 | ||
|
|
c793daa79a | ||
|
|
71b436aebe | ||
|
|
06e108da5b | ||
|
|
5677c58dd2 | ||
|
|
58ca801e30 | ||
|
|
e750d7caba | ||
|
|
3c0964ef0e | ||
|
|
33613cdf1c | ||
|
|
abfe174825 | ||
|
|
c750f469bb | ||
|
|
c7ac56d5cc | ||
|
|
6601f44013 | ||
|
|
b7baf862b6 | ||
|
|
ca79f4cf21 | ||
|
|
58ffbe8c74 | ||
|
|
dfa7b995fc | ||
|
|
59c65fe6ee | ||
|
|
087c042c14 | ||
|
|
d1ee488ffd | ||
|
|
34100bc580 | ||
|
|
22d91517fb | ||
|
|
1c088bd4e0 | ||
|
|
fd5bbb7f5d | ||
|
|
426d39bec0 | ||
|
|
8244c2dfb2 | ||
|
|
e7f9d32f68 | ||
|
|
71158a0030 | ||
|
|
573ce14b7a | ||
|
|
00ef1f470f | ||
|
|
a9357034c8 | ||
|
|
a45f5157d4 | ||
|
|
0d1009b8db | ||
|
|
4f0416cd45 | ||
|
|
76655d76d5 | ||
|
|
3b38cbe9ac | ||
|
|
acf37b8850 | ||
|
|
f47a0699d3 | ||
|
|
8ae429b06b | ||
|
|
626dbbcb49 | ||
|
|
b623dd80fd | ||
|
|
3978a7c9f7 | ||
|
|
7d2acb7438 | ||
|
|
096032301c | ||
|
|
c3e99bf2ff | ||
|
|
9795642bc7 | ||
|
|
4281a432fb | ||
|
|
18df5589b1 | ||
|
|
79536eac2e | ||
|
|
6df82fca04 | ||
|
|
cc14123d27 | ||
|
|
bd5e7b87ff | ||
|
|
42568916d6 | ||
|
|
180803cd8a | ||
|
|
08fcb0ce01 | ||
|
|
120b4c9df7 | ||
|
|
0eb66c10f6 | ||
|
|
1a6b14a250 | ||
|
|
072c8569eb | ||
|
|
5b9378255b | ||
|
|
ac3cf16377 | ||
|
|
31154d20f6 | ||
|
|
f8031ac71a | ||
|
|
898ec6a454 | ||
|
|
9dbd54fdf6 | ||
|
|
934017384d | ||
|
|
aee3dc0d93 | ||
|
|
8046687ae7 | ||
|
|
a89ee796c1 | ||
|
|
af1d3c3edc | ||
|
|
e1a54c2781 | ||
|
|
2d9f7d49b5 | ||
|
|
d10b046033 | ||
|
|
1725c0ff65 | ||
|
|
b852756c82 | ||
|
|
f164d878d7 | ||
|
|
ecc10fffcb | ||
|
|
5c75b015ba | ||
|
|
65f7dc697e | ||
|
|
d981f0f899 | ||
|
|
ab50beefab | ||
|
|
58d1215fd6 | ||
|
|
1dc137c314 | ||
|
|
ca51e9bf5f | ||
|
|
c588583dfc | ||
|
|
57c7c53eae | ||
|
|
76a62d9992 | ||
|
|
575aa1c6b1 | ||
|
|
4867a61fd0 | ||
|
|
a63e8f350b | ||
|
|
6c1b4f28af | ||
|
|
09adccf752 | ||
|
|
79bb522dee | ||
|
|
2adc4bc7ca | ||
|
|
0a81d58051 | ||
|
|
cb84438778 | ||
|
|
b0a76d311c | ||
|
|
5604503d26 | ||
|
|
bf55092b3a | ||
|
|
8286e7f9af | ||
|
|
1255221550 | ||
|
|
f4062cd6e7 | ||
|
|
93377ae753 | ||
|
|
a43cd19efd | ||
|
|
e5eec000d3 | ||
|
|
e5c8a62b32 | ||
|
|
9ae1c145b6 | ||
|
|
eb8b75e4f9 | ||
|
|
7378b82adf | ||
|
|
6f3b588f3d | ||
|
|
a2154cf37c | ||
|
|
9dab5f8093 | ||
|
|
9c9469d2f6 | ||
|
|
94acc313b1 | ||
|
|
448398322f | ||
|
|
3a78339396 | ||
|
|
a925a70448 | ||
|
|
e283eacaa3 | ||
|
|
3df6b6baed | ||
|
|
b65526e040 | ||
|
|
673bbf73be | ||
|
|
094d22eaa8 | ||
|
|
0fdba5fdec | ||
|
|
cf0730be89 | ||
|
|
221e67fd12 | ||
|
|
f9074309d1 | ||
|
|
b2bdbb9e30 | ||
|
|
63d0cb9626 | ||
|
|
e3bb3ae4d1 | ||
|
|
31890005ac | ||
|
|
04a216dee1 | ||
|
|
5d403c1202 | ||
|
|
a2d92c67b3 | ||
|
|
0fec3d82a3 | ||
|
|
6530a64f97 | ||
|
|
656f02d652 | ||
|
|
0dbf3bba4d | ||
|
|
ea47c0c3c6 | ||
|
|
b4072c7892 | ||
|
|
e80cd1990a | ||
|
|
2585cc1db4 | ||
|
|
0225828445 | ||
|
|
63af93592d | ||
|
|
b87fcd0f25 | ||
|
|
23a6b3cc55 | ||
|
|
dac3d229fd | ||
|
|
e360d9c5df | ||
|
|
8f100fc027 | ||
|
|
06fb331ae4 | ||
|
|
2bcf02a779 | ||
|
|
1b24664b60 | ||
|
|
2ce96a2062 | ||
|
|
5d737ba328 | ||
|
|
bafe8ba780 | ||
|
|
b7ff40fd72 | ||
|
|
8e036b1c01 | ||
|
|
b016c18880 | ||
|
|
d17ae49155 | ||
|
|
6ef5cd25f5 | ||
|
|
c98f077a0e | ||
|
|
a1f58c8e13 | ||
|
|
37281b01e4 | ||
|
|
65b0a768af | ||
|
|
39af06d3b2 | ||
|
|
7d137dd612 | ||
|
|
ce5e6c18f0 | ||
|
|
3d445ca61a | ||
|
|
8566eaaa6c | ||
|
|
db1647569c | ||
|
|
204afb7eb1 | ||
|
|
37f82d4579 | ||
|
|
2ed440e65f | ||
|
|
57a5ec2206 | ||
|
|
f14bc0494b | ||
|
|
c4147f0125 | ||
|
|
cfd0c3cbe9 | ||
|
|
0d0e2732b5 | ||
|
|
0a7b072eeb | ||
|
|
af6e12ca01 | ||
|
|
5eba94fd9b | ||
|
|
e9756494d9 | ||
|
|
f7f919b5de | ||
|
|
6f434f3b07 | ||
|
|
8820851afa | ||
|
|
4582e955d0 | ||
|
|
e07395b3d5 | ||
|
|
3ad7d06976 | ||
|
|
f57cbb76e3 | ||
|
|
bb3151a2fe | ||
|
|
5b48d204a0 | ||
|
|
680d96882a | ||
|
|
7347356646 | ||
|
|
2652e7ed71 |
12
.env.example
12
.env.example
@@ -4,10 +4,13 @@ APP_KEY=
|
||||
APP_DEBUG=false
|
||||
APP_URL=http://localhost
|
||||
APP_DEMO=false
|
||||
APP_DATE_TIME_FORMAT="Y-m-d H:i:s"
|
||||
|
||||
PLOI_TOKEN=
|
||||
PLOI_CORE_TOKEN=
|
||||
|
||||
IMPERSONATION=false
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
@@ -26,6 +29,7 @@ SESSION_LIFETIME=120
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
REDIS_CLIENT=predis
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=smtp.mailtrap.io
|
||||
@@ -36,6 +40,10 @@ MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS=null
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
STRIPE_KEY=your-stripe-key
|
||||
STRIPE_SECRET=your-stripe-secret
|
||||
CASHIER_MODEL=App\Models\User
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
@@ -46,5 +54,5 @@ PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
|
||||
33
.github/workflows/run-tests.yml
vendored
Normal file
33
.github/workflows/run-tests.yml
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
name: "Run tests"
|
||||
|
||||
on:
|
||||
push:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Pest (PHP ${{ matrix.php }} – ${{ matrix.os }})
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
php: [8.2]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo, mysql
|
||||
coverage: none
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
composer install
|
||||
|
||||
- name: Execute tests
|
||||
run: vendor/bin/pest
|
||||
9
.gitignore
vendored
9
.gitignore
vendored
@@ -1,8 +1,10 @@
|
||||
/node_modules
|
||||
/node_modules.nosync
|
||||
/public/hot
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/vendor
|
||||
/vendor.nosync
|
||||
.env
|
||||
.env.backup
|
||||
.phpunit.result.cache
|
||||
@@ -12,3 +14,10 @@ npm-debug.log
|
||||
yarn-error.log
|
||||
.idea
|
||||
.php_cs.cache
|
||||
.php-cs-fixer.cache
|
||||
/public/js/resources*.js
|
||||
/storage/views/header.blade.php
|
||||
/storage/views/footer.blade.php
|
||||
rr
|
||||
.rr.yaml
|
||||
.DS_Store
|
||||
|
||||
@@ -8,11 +8,11 @@ $finder = Symfony\Component\Finder\Finder::create()
|
||||
->name('*.php')
|
||||
->notName('*.blade.php');
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
return (new PhpCsFixer\Config)
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'ordered_imports' => ['sortAlgorithm' => 'length'],
|
||||
'ordered_imports' => ['sort_algorithm' => 'length'],
|
||||
'no_unused_imports' => true,
|
||||
])
|
||||
->setFinder($finder);
|
||||
@@ -9,5 +9,5 @@ php:
|
||||
js:
|
||||
finder:
|
||||
not-name:
|
||||
- webpack.mix.js
|
||||
- vite.config.js
|
||||
css: true
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# Ploi Core
|
||||
|
||||
With Ploi Core, you'll power-launch your webhosting company.
|
||||
With Ploi Core, you'll power-launch your webhosting company.
|
||||
Using the ploi.io system as backbone you will be able to serve your customers your custom panel & feeling.
|
||||
|
||||
<p align="center"><img src="https://ploi-core.io/images/featured.png" width="100%"></p>
|
||||
<p align="center"><img src="https://ploi-core.io/images/og.jpg" width="100%"></p>
|
||||
|
||||
## Documentation
|
||||
|
||||
@@ -17,4 +17,4 @@ https://ploi.io
|
||||
|
||||
The contribution guide can be found inside our documentation:
|
||||
|
||||
https://docs.ploi-core.io/getting-started/contribution-guide
|
||||
https://docs.ploi-core.io/261-getting-started/639-contribution-guide
|
||||
|
||||
39
app/Actions/Provider/SynchronizeProviderAction.php
Normal file
39
app/Actions/Provider/SynchronizeProviderAction.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Provider;
|
||||
|
||||
use App\Models\Provider;
|
||||
use App\Services\Ploi\Ploi;
|
||||
|
||||
class SynchronizeProviderAction
|
||||
{
|
||||
public function execute(int $ploiProviderId): Provider
|
||||
{
|
||||
$ploiProvider = Ploi::make()->user()->serverProviders($ploiProviderId)->getData();
|
||||
|
||||
$provider = Provider::updateOrCreate([
|
||||
'ploi_id' => $ploiProvider->id,
|
||||
], [
|
||||
'label' => $ploiProvider->label,
|
||||
'name' => $ploiProvider->name,
|
||||
]);
|
||||
|
||||
foreach ($ploiProvider->provider->plans as $plan) {
|
||||
$provider->plans()->updateOrCreate([
|
||||
'plan_id' => $plan->id,
|
||||
], [
|
||||
'label' => $plan->name,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($ploiProvider->provider->regions as $region) {
|
||||
$provider->regions()->updateOrCreate([
|
||||
'region_id' => $region->id,
|
||||
], [
|
||||
'label' => $region->name,
|
||||
]);
|
||||
}
|
||||
|
||||
return $provider;
|
||||
}
|
||||
}
|
||||
57
app/Actions/Server/CreateServerAction.php
Normal file
57
app/Actions/Server/CreateServerAction.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Server;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Jobs\Servers\CreateServer;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\DataTransferObjects\ServerData;
|
||||
use App\Mail\Admin\Server\AdminServerCreatedEmail;
|
||||
|
||||
class CreateServerAction
|
||||
{
|
||||
public function execute(ServerData $serverData): Server
|
||||
{
|
||||
[$provider, $providerRegion, $providerPlan] = $this->determineProviderRegionPlan($serverData);
|
||||
|
||||
$server = $serverData->getUser()->servers()->create([
|
||||
'name' => $serverData->name,
|
||||
'database_type' => $serverData->database_type,
|
||||
'os' => setting('default_os', Server::OS_UBUNTU_22)
|
||||
]);
|
||||
|
||||
$server->provider()->associate($provider);
|
||||
$server->providerRegion()->associate($providerRegion);
|
||||
$server->providerPlan()->associate($providerPlan);
|
||||
$server->save();
|
||||
|
||||
dispatch(new CreateServer($server));
|
||||
|
||||
$this->sendAdminServerCreatedEmails($server);
|
||||
|
||||
return $server;
|
||||
}
|
||||
|
||||
protected function determineProviderRegionPlan(ServerData $serverData): array
|
||||
{
|
||||
$provider = $serverData->getUser()->package->providers()->findOrFail($serverData->provider_id);
|
||||
$region = $provider->regions()->findOrFail($serverData->provider_region_id);
|
||||
$plan = $provider->plans()->findOrFail($serverData->provider_plan_id);
|
||||
|
||||
return [$provider, $region, $plan];
|
||||
}
|
||||
|
||||
protected function sendAdminServerCreatedEmails(Server $server): void
|
||||
{
|
||||
if (! setting('receive_email_on_server_creation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admins = User::query()->where('role', User::ADMIN)->get();
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
Mail::to($admin)->send(new AdminServerCreatedEmail(auth()->user(), $server));
|
||||
}
|
||||
}
|
||||
}
|
||||
63
app/Actions/Server/SynchronizeServerAction.php
Normal file
63
app/Actions/Server/SynchronizeServerAction.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Server;
|
||||
|
||||
use Throwable;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class SynchronizeServerAction
|
||||
{
|
||||
public function execute(int $ploiServerId): Server|null
|
||||
{
|
||||
try {
|
||||
$serverData = Ploi::make()->server()->get($ploiServerId)->getData();
|
||||
} catch (Throwable $exception) {
|
||||
Notification::make()
|
||||
->title('An error has occurred: ' . $exception->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!$serverData){
|
||||
Notification::make()
|
||||
->title('Server synchronization')
|
||||
->body('It was not possible to synchronize servers, it seems the API key has the wrong scopes. Please make sure the Ploi API key you\'ve entered has all the scopes enabled.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$server = Server::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $serverData->id,
|
||||
], [
|
||||
'status' => $serverData->status,
|
||||
'name' => $serverData->name,
|
||||
'ip' => $serverData->ip_address,
|
||||
'ssh_port' => $serverData->ssh_port,
|
||||
'internal_ip' => $serverData->internal_ip,
|
||||
'available_php_versions' => $serverData->installed_php_versions,
|
||||
]);
|
||||
} catch (Throwable $exception) {
|
||||
Notification::make()
|
||||
->title('An error has occurred: ' . $exception->getMessage())
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('Server :server synchronized successfully.', ['server' => $server->name]))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
return $server;
|
||||
}
|
||||
}
|
||||
76
app/Actions/Site/CreateSiteAction.php
Normal file
76
app/Actions/Site/CreateSiteAction.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Site;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Jobs\Sites\CreateSite;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\DataTransferObjects\SiteData;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Mail\Admin\Site\AdminSiteCreatedEmail;
|
||||
|
||||
class CreateSiteAction
|
||||
{
|
||||
public function execute(SiteData $siteData): ?Site
|
||||
{
|
||||
$server = $this->determineServer($siteData);
|
||||
|
||||
if (! $server) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$site = $server->sites()->create($siteData->toArray());
|
||||
|
||||
$siteData->getUser()->sites()->save($site);
|
||||
|
||||
dispatch(new CreateSite($site));
|
||||
|
||||
$siteData->getUser()->systemLogs()->create([
|
||||
'title' => 'New site :site created',
|
||||
'description' => 'A new site has been created',
|
||||
])->model()->associate($site)->save();
|
||||
|
||||
$this->sendAdminSiteCreatedEmails($server, $site, $siteData->getUser());
|
||||
|
||||
return $site;
|
||||
}
|
||||
|
||||
protected function determineServer(SiteData $siteData): ?Server
|
||||
{
|
||||
if ($siteData->server_id) {
|
||||
return $siteData->getUser()->servers()->findOrFail($siteData->server_id);
|
||||
}
|
||||
|
||||
$server = Server::query()
|
||||
->where('maximum_sites', '>', 0)
|
||||
->where(function ($query) use ($siteData) {
|
||||
return $query
|
||||
->where(fn ($query) => $query->whereHas('users', fn ($query) => $query->where('user_id', $siteData->getUser()->id)))
|
||||
->orWhere(function ($query) {
|
||||
return $query->doesntHave('users');
|
||||
});
|
||||
})
|
||||
->withCount('sites')
|
||||
->inRandomOrder()
|
||||
->first();
|
||||
|
||||
return $server && $server->sites_count < $server->maximum_sites
|
||||
? $server
|
||||
: null;
|
||||
}
|
||||
|
||||
protected function sendAdminSiteCreatedEmails(Server $server, Model|Site $site, User $user): void
|
||||
{
|
||||
if (! setting('receive_email_on_site_creation')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admins = User::where('role', User::ADMIN)->get();
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
Mail::to($admin)->send(new AdminSiteCreatedEmail(user: $user, server: $server, site: $site));
|
||||
}
|
||||
}
|
||||
}
|
||||
55
app/Actions/Site/SynchronizeSiteAction.php
Normal file
55
app/Actions/Site/SynchronizeSiteAction.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Site;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class SynchronizeSiteAction
|
||||
{
|
||||
public function execute(int $ploiServerId, int $ploiSiteId): Site
|
||||
{
|
||||
$siteData = Ploi::make()->server($ploiServerId)->sites()->get($ploiSiteId)->getData();
|
||||
|
||||
$server = Server::query()
|
||||
->where('ploi_id', $siteData->server_id)
|
||||
->firstOrFail();
|
||||
|
||||
$site = Site::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $siteData->id,
|
||||
], [
|
||||
'domain' => $siteData->domain,
|
||||
'php_version' => $siteData->php_version,
|
||||
'project' => $siteData->project_type,
|
||||
]);
|
||||
|
||||
$site->status = $siteData->status;
|
||||
$site->server_id = $server->id;
|
||||
$site->save();
|
||||
|
||||
$certificates = Ploi::make()->server($siteData->server_id)->sites($siteData->id)->certificates()->get()->getData();
|
||||
|
||||
if ($certificates) {
|
||||
foreach ($certificates as $certificate) {
|
||||
$site->certificates()->updateOrCreate([
|
||||
'ploi_id' => $certificate->id,
|
||||
], [
|
||||
'status' => $certificate->status,
|
||||
'ploi_id' => $certificate->id,
|
||||
'domain' => $certificate->domain,
|
||||
'type' => $certificate->type,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('Site :site synchronized successfully.', ['site' => $site->domain]))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
return $site;
|
||||
}
|
||||
}
|
||||
50
app/Actions/User/DeleteUserAction.php
Normal file
50
app/Actions/User/DeleteUserAction.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\User;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Jobs\Sites\DeleteSite;
|
||||
use App\Jobs\Servers\DeleteServer;
|
||||
|
||||
class DeleteUserAction
|
||||
{
|
||||
public function execute(User $user, bool $removeAllData): void
|
||||
{
|
||||
if ($removeAllData) {
|
||||
$this->removeAllData($user);
|
||||
}
|
||||
|
||||
// The next items are already being deleted by the "deleting" event:
|
||||
// systemLogs, servers detached, sites detached, supportTickets, supportTicketReplies, userProviders
|
||||
$user->delete();
|
||||
}
|
||||
|
||||
protected function removeAllData(User $user): void
|
||||
{
|
||||
$user
|
||||
->sites()
|
||||
->withCount('users')
|
||||
->get()
|
||||
->filter(fn (Site $site) => $site->users_count === 1)
|
||||
->each(function (Site $site) {
|
||||
dispatch(new DeleteSite($site->server->ploi_id, $site->ploi_id));
|
||||
|
||||
// Deletes databases, redirects, cronjobs, certificates.
|
||||
$site->delete();
|
||||
});
|
||||
|
||||
$user
|
||||
->servers()
|
||||
->withCount('users')
|
||||
->get()
|
||||
->filter(fn (Server $server) => $server->users_count === 1)
|
||||
->each(function (Server $server) {
|
||||
dispatch(new DeleteServer($server->ploi_id));
|
||||
|
||||
// Deletes databases, redirects, cronjobs, certificates.
|
||||
$server->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
44
app/Casts/PermissionCast.php
Normal file
44
app/Casts/PermissionCast.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
|
||||
class PermissionCast implements CastsAttributes
|
||||
{
|
||||
/**
|
||||
* Cast the given value.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($model, $key, $value, $attributes)
|
||||
{
|
||||
if (!$value) {
|
||||
return [
|
||||
'create' => false,
|
||||
'update' => false,
|
||||
'delete' => false,
|
||||
];
|
||||
}
|
||||
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the given value for storage.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param array $value
|
||||
* @param array $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function set($model, $key, $value, $attributes)
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
}
|
||||
26
app/Casts/SiteAlias.php
Normal file
26
app/Casts/SiteAlias.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Casts;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||
|
||||
class SiteAlias implements CastsAttributes
|
||||
{
|
||||
public function get($model, string $key, $value, array $attributes)
|
||||
{
|
||||
if (!$value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = json_decode($value, true);
|
||||
|
||||
sort($data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function set($model, string $key, $value, array $attributes)
|
||||
{
|
||||
return json_encode($value);
|
||||
}
|
||||
}
|
||||
60
app/Console/Commands/Core/Cleanup.php
Normal file
60
app/Console/Commands/Core/Cleanup.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use App\Models\SystemLog;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Cleanup extends Command
|
||||
{
|
||||
protected $signature = 'core:cleanup';
|
||||
|
||||
protected $description = 'Clean up any old logs';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if (!setting('rotate_logs_after')) {
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
$rotationDate = $this->getRotationDate();
|
||||
|
||||
$rotated = SystemLog::query()
|
||||
->where('created_at', '<', $rotationDate)
|
||||
->delete();
|
||||
|
||||
$this->info('Rotated ' . $rotated . ' system logs!');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
|
||||
protected function getRotationDate()
|
||||
{
|
||||
switch (setting('rotate_logs_after')) {
|
||||
case 'weeks-1':
|
||||
return now()->subWeek();
|
||||
break;
|
||||
case 'months-1':
|
||||
return now()->subMonth();
|
||||
break;
|
||||
case 'months-3':
|
||||
return now()->subMonths(3);
|
||||
break;
|
||||
case 'months-6':
|
||||
return now()->subMonths(6);
|
||||
break;
|
||||
case 'years-1':
|
||||
return now()->subYear();
|
||||
break;
|
||||
case 'years-2':
|
||||
return now()->subYears(2);
|
||||
break;
|
||||
case 'years-3':
|
||||
return now()->subYears(3);
|
||||
break;
|
||||
case 'years-4':
|
||||
return now()->subYears(4);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
31
app/Console/Commands/Core/Css.php
Normal file
31
app/Console/Commands/Core/Css.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class Css extends Command
|
||||
{
|
||||
protected $signature = 'core:css';
|
||||
|
||||
protected $description = 'Generates an theme.css file for you to customize';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if (file_exists(storage_path('app/public/theme.css')) && !$this->confirm('You seem to already have a theme.css published, are you sure you want to overwrite?')) {
|
||||
$this->warn('Aborted publishing of theme.css.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->info('Publishing theme.css file..');
|
||||
|
||||
(new Filesystem)->copy(
|
||||
__DIR__ . '/stubs/theme.css',
|
||||
storage_path('app/public/theme.css')
|
||||
);
|
||||
|
||||
$this->info('Done! You can edit the theme.css file inside storage/public/theme.css');
|
||||
}
|
||||
}
|
||||
31
app/Console/Commands/Core/CssBackup.php
Normal file
31
app/Console/Commands/Core/CssBackup.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
class CssBackup extends Command
|
||||
{
|
||||
protected $signature = 'core:css-backup';
|
||||
|
||||
protected $description = 'Creates a backup from your own created theme.css';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
if (!file_exists(storage_path('app/public/theme.css'))) {
|
||||
$this->warn('There is no custom theme.css, aborting backup.');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->info('Backing up theme.css file..');
|
||||
|
||||
(new Filesystem)->copy(
|
||||
storage_path('app/public/theme.css'),
|
||||
storage_path('app/public/theme-backup.css')
|
||||
);
|
||||
|
||||
$this->info('Done! You can find the CSS backup file here storage/public/theme-backup.css');
|
||||
}
|
||||
}
|
||||
@@ -7,29 +7,25 @@ use App\Models\User;
|
||||
use RuntimeException;
|
||||
use App\Models\Package;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Console\Command;
|
||||
use App\Services\VersionChecker;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class Install extends Command
|
||||
{
|
||||
protected $company;
|
||||
protected $signature = 'core:install';
|
||||
protected $signature = 'core:install {--force}';
|
||||
protected $description = 'Installation command for Ploi Core';
|
||||
protected $versionChecker;
|
||||
protected $installationFile = 'app/installation';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->versionChecker = (new VersionChecker)->getVersions();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->init();
|
||||
$this->intro();
|
||||
$this->isInstalled();
|
||||
$this->checkApplicationKey();
|
||||
@@ -40,35 +36,53 @@ class Install extends Command
|
||||
$this->askAboutDefaultPackages();
|
||||
$this->checkApplicationUrl();
|
||||
$this->createInstallationFile();
|
||||
$this->linkStorage();
|
||||
|
||||
$this->info('Succes! Installation has finished.');
|
||||
$this->info('Success! Installation has finished.');
|
||||
$this->line(' ');
|
||||
$this->writeSeparationLine();
|
||||
$this->info('Make sure to also setup emailing, the cronjob and the queue worker.');
|
||||
$this->line(' ');
|
||||
$this->info('Setting up emailing: https://docs.ploi-core.io/261-getting-started/918-setting-up-email');
|
||||
$this->info('Setting up cronjob & queue worker: https://docs.ploi-core.io/261-getting-started/638-installation');
|
||||
$this->writeSeparationLine();
|
||||
$this->line(' ');
|
||||
$this->info('Visit your platform at ' . env('APP_URL'));
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->versionChecker = (new VersionChecker)->getVersions();
|
||||
}
|
||||
|
||||
protected function askAboutAdministrationAccount()
|
||||
{
|
||||
$this->info('Let\'s start by setting up your administration account.');
|
||||
if (!User::query()->where('role', User::ADMIN)->count()) {
|
||||
$this->info('Let\'s start by setting up your administration account.');
|
||||
|
||||
$name = $this->ask('What is your name', $this->company['user_name']);
|
||||
$email = $this->ask('What is your e-mail address', $this->company['email']);
|
||||
$password = $this->secret('What password do you desire');
|
||||
$name = $this->ask('What is your name', $this->company['user_name']);
|
||||
$email = $this->ask('What is your e-mail address', $this->company['email']);
|
||||
$password = $this->secret('What password do you desire');
|
||||
|
||||
$check = User::where('email', $email)->count();
|
||||
$check = User::where('email', $email)->count();
|
||||
|
||||
if ($check) {
|
||||
$this->line('');
|
||||
$this->comment('This user is already present in your system, please refresh your database or use different credentials.');
|
||||
$this->comment('Aborting installation..');
|
||||
if ($check) {
|
||||
$this->line('');
|
||||
$this->comment('This user is already present in your system, please refresh your database or use different credentials.');
|
||||
$this->comment('Aborting installation..');
|
||||
|
||||
exit();
|
||||
exit();
|
||||
}
|
||||
|
||||
User::forceCreate([
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'role' => User::ADMIN
|
||||
]);
|
||||
} else {
|
||||
$this->line('Already found a administrator user in your system. Use that user to login.');
|
||||
}
|
||||
|
||||
User::forceCreate([
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'password' => $password,
|
||||
'role' => User::ADMIN
|
||||
]);
|
||||
}
|
||||
|
||||
protected function askAboutDefaultPackages()
|
||||
@@ -85,16 +99,46 @@ class Install extends Command
|
||||
Package::create([
|
||||
'name' => 'Basic',
|
||||
'maximum_sites' => 5,
|
||||
'site_permissions' => [
|
||||
'create' => true,
|
||||
'update' => true,
|
||||
'delete' => true
|
||||
],
|
||||
'server_permissions' => [
|
||||
'create' => false,
|
||||
'update' => false,
|
||||
'delete' => false
|
||||
]
|
||||
]);
|
||||
|
||||
Package::create([
|
||||
'name' => 'Professional',
|
||||
'maximum_sites' => 5,
|
||||
'maximum_sites' => 30,
|
||||
'site_permissions' => [
|
||||
'create' => true,
|
||||
'update' => true,
|
||||
'delete' => true
|
||||
],
|
||||
'server_permissions' => [
|
||||
'create' => false,
|
||||
'update' => false,
|
||||
'delete' => false
|
||||
]
|
||||
]);
|
||||
|
||||
Package::create([
|
||||
'name' => 'Unlimited',
|
||||
'maximum_sites' => 0,
|
||||
'site_permissions' => [
|
||||
'create' => true,
|
||||
'update' => true,
|
||||
'delete' => true
|
||||
],
|
||||
'server_permissions' => [
|
||||
'create' => false,
|
||||
'update' => false,
|
||||
'delete' => false
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -109,7 +153,9 @@ class Install extends Command
|
||||
->get((new Ploi)->url . 'ping');
|
||||
|
||||
if (!$response->ok() || !$response->json()) {
|
||||
return false;
|
||||
return [
|
||||
'error' => Arr::get($response->json(), 'message', 'An unknown error has occurred.')
|
||||
];
|
||||
}
|
||||
|
||||
return $response->json();
|
||||
@@ -124,7 +170,7 @@ class Install extends Command
|
||||
|
||||
protected function intro()
|
||||
{
|
||||
$this->info('*---------------------------------------------------------------------------*');
|
||||
$this->writeSeparationLine();
|
||||
$this->line('Ploi Core Installation');
|
||||
$this->line('Ploi Core version: ' . $this->versionChecker->currentVersion);
|
||||
$this->line('Ploi Core remote: ' . $this->versionChecker->remoteVersion);
|
||||
@@ -134,13 +180,13 @@ class Install extends Command
|
||||
$this->line('Website: https://ploi-core.io');
|
||||
$this->line('E-mail: core@ploi.io');
|
||||
$this->line('Terms of service: https://ploi-core.io/terms');
|
||||
$this->info('*---------------------------------------------------------------------------*');
|
||||
$this->writeSeparationLine();
|
||||
$this->line('');
|
||||
}
|
||||
|
||||
protected function isInstalled()
|
||||
{
|
||||
if (file_exists(storage_path($this->installationFile))) {
|
||||
if (file_exists(storage_path($this->installationFile)) && !$this->option('force')) {
|
||||
$this->line('');
|
||||
$this->comment('Ploi Core has already been installed before.');
|
||||
$this->comment('If you still want to start installation, remove this file to continue: ./storage/' . $this->installationFile);
|
||||
@@ -156,9 +202,9 @@ class Install extends Command
|
||||
{
|
||||
if (!config('app.key')) {
|
||||
$this->call('key:generate');
|
||||
}
|
||||
|
||||
$this->info('Application key has been set');
|
||||
$this->info('Application key has been set');
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkApplicationUrl()
|
||||
@@ -174,6 +220,11 @@ class Install extends Command
|
||||
file_put_contents(storage_path($this->installationFile), json_encode($this->getInstallationPayload(), JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
protected function linkStorage()
|
||||
{
|
||||
Artisan::call('storage:link');
|
||||
}
|
||||
|
||||
protected function createDatabaseCredentials(): bool
|
||||
{
|
||||
$storeCredentials = $this->confirm(
|
||||
@@ -240,6 +291,18 @@ class Install extends Command
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($this->company['error'])) {
|
||||
$this->error($this->company['error']);
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($this->company['user']['subscription'] !== 'unlimited') {
|
||||
$this->error('Your subscription does not cover the usage of Ploi Core. Please upgrade your subscription to Unlimited.');
|
||||
|
||||
exit();
|
||||
}
|
||||
|
||||
$this->writeToEnvironmentFile('PLOI_TOKEN', $ploiApiToken);
|
||||
$this->writeToEnvironmentFile('PLOI_CORE_TOKEN', $ploiCoreKey);
|
||||
|
||||
@@ -252,7 +315,7 @@ class Install extends Command
|
||||
protected function runDatabaseMigrations()
|
||||
{
|
||||
$this->info('Running database migrations..');
|
||||
$this->call('migrate');
|
||||
$this->call('migrate', ['--force' => true]);
|
||||
$this->info('Database migrations successful');
|
||||
}
|
||||
|
||||
@@ -343,4 +406,9 @@ class Install extends Command
|
||||
{
|
||||
$this->laravel['config'][$key] = $value;
|
||||
}
|
||||
|
||||
protected function writeSeparationLine()
|
||||
{
|
||||
$this->info('*---------------------------------------------------------------------------*');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class Synchronize extends Command
|
||||
{
|
||||
protected $signature = 'core:synchronize';
|
||||
|
||||
protected $description = 'Synchronze data';
|
||||
protected $description = 'Synchronize data';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
24
app/Console/Commands/Core/Trial.php
Normal file
24
app/Console/Commands/Core/Trial.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Core;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class Trial extends Command
|
||||
{
|
||||
protected $signature = 'core:trial';
|
||||
|
||||
protected $description = 'Check for expired trials';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
User::query()
|
||||
->where('trial_ends_at', '<', now())
|
||||
->each(function (User $user) {
|
||||
$user->trial_ends_at = null;
|
||||
$user->package_id = setting('default_package');
|
||||
$user->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
78
app/Console/Commands/Core/stubs/theme.css
vendored
Normal file
78
app/Console/Commands/Core/stubs/theme.css
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
:root {
|
||||
--font-body: 'Inter', sans-serif;
|
||||
|
||||
--color-white: #fff;
|
||||
--color-gray-1: #f7f7f7;
|
||||
--color-gray-2: #e6e6e6;
|
||||
--color-gray-3: #cacaca;
|
||||
--color-gray-4: #888;
|
||||
--color-gray-5: #666;
|
||||
--color-gray-6: #2f2f2f;
|
||||
--color-gray-7: #1b1a1a;
|
||||
--color-gray-8: #101010;
|
||||
|
||||
--color-primary: #1b8ae8;
|
||||
--color-success: #17b35d;
|
||||
--color-warning: #f5a623;
|
||||
--color-danger: #c90c4c;
|
||||
|
||||
--color-text-high-emphasis: var(--color-gray-8);
|
||||
--color-text-medium-emphasis: var(--color-gray-5);
|
||||
--color-text-low-emphasis: var(--color-gray-3);
|
||||
|
||||
--color-text-on-primary: var(--color-white);
|
||||
--color-text-on-success: var(--color-gray-8);
|
||||
--color-text-on-warning: var(--color-white);
|
||||
--color-text-on-danger: var(--color-white);
|
||||
|
||||
--color-border-high-emphasis: var(--color-gray-4);
|
||||
--color-border-medium-emphasis: var(--color-gray-3);
|
||||
--color-border-low-emphasis: var(--color-gray-2);
|
||||
|
||||
--color-backdrop: rgba(0, 0, 0, 0.5);
|
||||
--color-overlay: rgba(255, 255, 255, 0.8);
|
||||
--color-surface-1: var(--color-white);
|
||||
--color-surface-2: var(--color-gray-1);
|
||||
--color-surface-3: var(--color-white);
|
||||
|
||||
--border-radius: 0.5rem;
|
||||
--border-radius-avatar: 4rem;
|
||||
--border-radius-circle: 100%;
|
||||
|
||||
--top-bar-container: 64rem;
|
||||
--top-bar-logo-height: 3.5rem;
|
||||
--top-bar-background-color: var(--color-surface-1);
|
||||
--top-bar-text-color: var(--color-text-medium-emphasis);
|
||||
|
||||
--tab-bar-background-color: var(--color-surface-2);
|
||||
--tab-bar-item-active-background-color: var(--color-surface-1);
|
||||
--tab-bar-item-text-color: var(--color-text-medium-emphasis);
|
||||
--tab-bar-item-active-text-color: var(--color-text-high-emphasis);
|
||||
|
||||
--breadcrumbs-text-color: var(--color-text-medium-emphasis);
|
||||
}
|
||||
|
||||
.theme--dark {
|
||||
--color-primary: #63a6f5;
|
||||
--color-success: #50e3c2;
|
||||
--color-warning: #f5a623;
|
||||
--color-danger: #d4667c;
|
||||
|
||||
--color-text-high-emphasis: var(--color-white);
|
||||
--color-text-medium-emphasis: var(--color-gray-3);
|
||||
--color-text-low-emphasis: var(--color-gray-5);
|
||||
|
||||
--color-text-on-primary: var(--color-gray-7);
|
||||
--color-text-on-success: var(--color-gray-7);
|
||||
--color-text-on-warning: var(--color-gray-7);
|
||||
--color-text-on-danger: var(--color-gray-7);
|
||||
|
||||
--color-border-high-emphasis: var(--color-gray-4);
|
||||
--color-border-medium-emphasis: var(--color-gray-5);
|
||||
--color-border-low-emphasis: var(--color-gray-6);
|
||||
|
||||
--color-surface-1: var(--color-gray-7);
|
||||
--color-surface-2: var(--color-gray-6);
|
||||
--color-surface-3: var(--color-gray-6);
|
||||
--color-overlay: rgba(0, 0, 0, 0.8);
|
||||
}
|
||||
@@ -3,7 +3,11 @@
|
||||
namespace App\Console;
|
||||
|
||||
use App\Jobs\Core\Ping;
|
||||
use App\Console\Commands\Core\Css;
|
||||
use App\Console\Commands\Core\Trial;
|
||||
use App\Console\Commands\Core\Cleanup;
|
||||
use App\Console\Commands\Core\Install;
|
||||
use App\Console\Commands\Core\CssBackup;
|
||||
use App\Console\Commands\Core\Synchronize;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
@@ -11,8 +15,12 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
protected $commands = [
|
||||
Css::class,
|
||||
CssBackup::class,
|
||||
Install::class,
|
||||
Synchronize::class,
|
||||
Cleanup::class,
|
||||
Trial::class,
|
||||
];
|
||||
|
||||
protected function schedule(Schedule $schedule)
|
||||
@@ -20,5 +28,8 @@ class Kernel extends ConsoleKernel
|
||||
$schedule->call(function () {
|
||||
dispatch(new Ping())->delay(now()->addMinutes(rand(1, 30)));
|
||||
})->dailyAt('02:00');
|
||||
|
||||
$schedule->command('core:cleanup')->daily();
|
||||
$schedule->command('core:trial')->dailyAt('10:00');
|
||||
}
|
||||
}
|
||||
|
||||
26
app/DataTransferObjects/PackageData.php
Normal file
26
app/DataTransferObjects/PackageData.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
|
||||
class PackageData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
// Add validation attributes to this class if we add additional API-endpoints.
|
||||
public int $id,
|
||||
public ?string $name,
|
||||
public ?int $maximum_servers,
|
||||
public ?int $maximum_sites,
|
||||
public float $price_hourly,
|
||||
public float $price_monthly,
|
||||
public float $price_yearly,
|
||||
public ?string $stripe_plan_id,
|
||||
public string $currency,
|
||||
public array $server_permissions,
|
||||
public array $site_permissions,
|
||||
public Carbon $created_at,
|
||||
) {
|
||||
}
|
||||
}
|
||||
49
app/DataTransferObjects/ServerData.php
Normal file
49
app/DataTransferObjects/ServerData.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Models\Provider;
|
||||
use App\Models\ProviderPlan;
|
||||
use App\Models\ProviderRegion;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use Spatie\LaravelData\Attributes\Validation\In;
|
||||
use Spatie\LaravelData\Attributes\Validation\Max;
|
||||
use Spatie\LaravelData\Attributes\Validation\NotIn;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use Spatie\LaravelData\Attributes\Validation\AlphaDash;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
|
||||
class ServerData extends Data
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
#[StringType]
|
||||
public ?string $status = null,
|
||||
#[StringType, AlphaDash, Max(40)]
|
||||
public string $name,
|
||||
#[NotIn(0), Exists(Provider::class, 'id')]
|
||||
public int $provider_id,
|
||||
#[NotIn(0), Exists(ProviderRegion::class, 'id')]
|
||||
public int $provider_region_id,
|
||||
#[NotIn(0), Exists(ProviderPlan::class, 'id')]
|
||||
public int $provider_plan_id,
|
||||
#[StringType, In(['mysql', 'mariadb', 'postgresql', 'postgresql13'])]
|
||||
public string $database_type,
|
||||
#[Exists(User::class, 'id'), IntegerType]
|
||||
public ?int $user_id = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function fromModel(Server $server): static
|
||||
{
|
||||
return static::from(array_merge($server->toArray(), ['user_id' => $server->user->id]));
|
||||
}
|
||||
}
|
||||
61
app/DataTransferObjects/SiteData.php
Normal file
61
app/DataTransferObjects/SiteData.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use App\Models\Server;
|
||||
use App\Rules\Hostname;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Rules\ValidateMaximumSites;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use App\DataTransferObjects\Support\Rules\CustomRule;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
use App\DataTransferObjects\Support\Concerns\BelongsToUser;
|
||||
|
||||
class SiteData extends Data
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $status = null,
|
||||
#[Exists(Server::class, 'id'), IntegerType]
|
||||
public ?int $server_id = null,
|
||||
#[StringType, CustomRule(Hostname::class, ValidateMaximumSites::class)]
|
||||
public ?string $domain = null,
|
||||
#[Exists(User::class, 'id'), IntegerType]
|
||||
public ?int $user_id = null,
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
}
|
||||
|
||||
public static function authorize(): bool
|
||||
{
|
||||
if (auth()->guest()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return auth()->user()->can('create', Site::class);
|
||||
}
|
||||
|
||||
public static function fromModel(Site $site): static
|
||||
{
|
||||
return static::from(array_merge($site->toArray(), ['user_id' => $site->user->id]));
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return Arr::only(parent::toArray(), [
|
||||
'id',
|
||||
'status',
|
||||
'server_id',
|
||||
'domain',
|
||||
'user_id',
|
||||
'created_at',
|
||||
]);
|
||||
}
|
||||
}
|
||||
15
app/DataTransferObjects/Support/Casts/CarbonCast.php
Normal file
15
app/DataTransferObjects/Support/Casts/CarbonCast.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Casts;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Spatie\LaravelData\Casts\Cast;
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
|
||||
class CarbonCast implements Cast
|
||||
{
|
||||
public function cast(DataProperty $property, mixed $value, array $context): Carbon
|
||||
{
|
||||
return Carbon::parse($value);
|
||||
}
|
||||
}
|
||||
13
app/DataTransferObjects/Support/Concerns/BelongsToUser.php
Normal file
13
app/DataTransferObjects/Support/Concerns/BelongsToUser.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Concerns;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
trait BelongsToUser
|
||||
{
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return User::find($this->user_id);
|
||||
}
|
||||
}
|
||||
14
app/DataTransferObjects/Support/Data.php
Normal file
14
app/DataTransferObjects/Support/Data.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
class Data extends \Spatie\LaravelData\Data
|
||||
{
|
||||
/**
|
||||
* When working with paginated data, we want to include pagination details in JSON
|
||||
* responses from the API. However, due to legacy requirements Ploi Core is using
|
||||
* a different structure than this package assumes. Therefore, we will override
|
||||
* the data collection, register a custom transformer and output the structure.
|
||||
*/
|
||||
protected static string $_paginatedCollectionClass = PaginatedDataCollection::class;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
class DataCollectableTransformer extends \Spatie\LaravelData\Transformers\DataCollectableTransformer
|
||||
{
|
||||
protected function wrapPaginatedArray(array $paginated): array
|
||||
{
|
||||
$wrapKey = $this->wrap->getKey() ?? 'data';
|
||||
|
||||
return [
|
||||
$wrapKey => $paginated['data'],
|
||||
'links' => [
|
||||
'first' => $paginated['first_page_url'],
|
||||
'last' => $paginated['last_page_url'],
|
||||
'prev' => $paginated['prev_page_url'],
|
||||
'next' => $paginated['next_page_url'],
|
||||
],
|
||||
'meta' => [
|
||||
'current_page' => $paginated['current_page'],
|
||||
'from' => $paginated['from'],
|
||||
'last_page' => $paginated['last_page'],
|
||||
'links' => $paginated['links'],
|
||||
'path' => $paginated['path'],
|
||||
'per_page' => $paginated['per_page'],
|
||||
'to' => $paginated['to'],
|
||||
'total' => $paginated['total'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
23
app/DataTransferObjects/Support/PaginatedDataCollection.php
Normal file
23
app/DataTransferObjects/Support/PaginatedDataCollection.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support;
|
||||
|
||||
use Spatie\LaravelData\Support\Wrapping\WrapExecutionType;
|
||||
|
||||
class PaginatedDataCollection extends \Spatie\LaravelData\PaginatedDataCollection
|
||||
{
|
||||
public function transform(bool $transformValues = true, WrapExecutionType $wrapExecutionType = WrapExecutionType::Disabled, bool $mapPropertyNames = true): array
|
||||
{
|
||||
$transformer = new DataCollectableTransformer(
|
||||
$this->dataClass,
|
||||
$transformValues,
|
||||
$wrapExecutionType,
|
||||
$mapPropertyNames,
|
||||
$this->getPartialTrees(),
|
||||
$this->items,
|
||||
$this->getWrap(),
|
||||
);
|
||||
|
||||
return $transformer->transform();
|
||||
}
|
||||
}
|
||||
29
app/DataTransferObjects/Support/Rules/CustomRule.php
Normal file
29
app/DataTransferObjects/Support/Rules/CustomRule.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Rules;
|
||||
|
||||
use Attribute;
|
||||
use Spatie\LaravelData\Support\Validation\ValidationPath;
|
||||
use Spatie\LaravelData\Attributes\Validation\CustomValidationAttribute;
|
||||
|
||||
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_PARAMETER)]
|
||||
class CustomRule extends CustomValidationAttribute
|
||||
{
|
||||
protected array $rules = [];
|
||||
|
||||
public function __construct(...$rules)
|
||||
{
|
||||
$this->rules = $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<object|string>|object|string
|
||||
*/
|
||||
public function getRules(ValidationPath $path): array|object|string
|
||||
{
|
||||
return array_map(
|
||||
fn (string $ruleClass) => new $ruleClass(),
|
||||
$this->rules
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects\Support\Transformers;
|
||||
|
||||
use Illuminate\Support\Carbon;
|
||||
use Spatie\LaravelData\Support\DataProperty;
|
||||
use Spatie\LaravelData\Transformers\Transformer;
|
||||
|
||||
class CarbonTransformer implements Transformer
|
||||
{
|
||||
public function transform(DataProperty $property, mixed $value): string
|
||||
{
|
||||
/** @var Carbon $value */
|
||||
return $value->toISOString();
|
||||
}
|
||||
}
|
||||
37
app/DataTransferObjects/UserData.php
Normal file
37
app/DataTransferObjects/UserData.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTransferObjects;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Package;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\DataTransferObjects\Support\Data;
|
||||
use Spatie\LaravelData\Attributes\Validation\Max;
|
||||
use Spatie\LaravelData\Attributes\Validation\Email;
|
||||
use Spatie\LaravelData\Attributes\Validation\Exists;
|
||||
use Spatie\LaravelData\Attributes\Validation\Unique;
|
||||
use Spatie\LaravelData\Attributes\Validation\StringType;
|
||||
use Spatie\LaravelData\Attributes\Validation\BooleanType;
|
||||
use Spatie\LaravelData\Attributes\Validation\IntegerType;
|
||||
|
||||
class UserData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public ?int $id = null,
|
||||
public ?string $avatar = null,
|
||||
#[StringType, Max(255)]
|
||||
public ?string $name = null,
|
||||
#[StringType, Email, Max(255), Unique(User::class)]
|
||||
public ?string $email = null,
|
||||
#[Exists(Package::class, 'id'), IntegerType]
|
||||
public ?int $package_id = null,
|
||||
#[StringType]
|
||||
public ?string $blocked = null,
|
||||
#[StringType]
|
||||
public ?string $language = 'en',
|
||||
#[BooleanType]
|
||||
public ?bool $requires_password_for_ftp = true,
|
||||
public ?Carbon $created_at = null,
|
||||
) {
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,12 @@
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Middleware\SetLocale;
|
||||
use App\Http\Middleware\HandleInertiaRequests;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
@@ -29,10 +34,10 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Throwable $exception
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
@@ -42,24 +47,25 @@ class Handler extends ExceptionHandler
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Throwable $exception
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
* @param Request $request
|
||||
* @param Throwable $exception
|
||||
* @return Response
|
||||
*
|
||||
* @throws \Throwable
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function render($request, Throwable $exception)
|
||||
{
|
||||
$response = parent::render($request, $exception);
|
||||
|
||||
if (in_array($response->status(), [404, 403])) {
|
||||
\Route::any($request->path(), function () use ($exception, $request) {
|
||||
return parent::render($request, $exception);
|
||||
})->middleware('web');
|
||||
// Only return an Inertia-response when there are special Vue-templates (403 and 404) and when it isn't an API request.
|
||||
if (in_array($response->status(), [403, 404]) && ! $request->routeIs('api.*')) {
|
||||
inertia()->share([
|
||||
'translations' => SetLocale::getTranslations()
|
||||
]);
|
||||
|
||||
return inertia()->render('Errors/' . $response->status(), ['status' => $response->status()])
|
||||
->toResponse($request)
|
||||
->setStatusCode($response->status());
|
||||
return app(HandleInertiaRequests::class)
|
||||
->handle($request, fn () => inertia()->render('Errors/' . $response->status(), ['status' => $response->status()])
|
||||
->toResponse($request));
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
||||
184
app/Filament/Pages/Settings.php
Normal file
184
app/Filament/Pages/Settings.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Forms;
|
||||
use App\Models\Server;
|
||||
use App\Models\Package;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
|
||||
class Settings extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cog';
|
||||
|
||||
protected static string $view = 'filament.pages.settings';
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
cache()->forget('core.settings');
|
||||
|
||||
$this->form->fill([
|
||||
'logo' => setting('logo'),
|
||||
'name' => setting('name'),
|
||||
'email' => setting('email'),
|
||||
'support_emails' => setting('support_emails'),
|
||||
'default_package' => setting('default_package'),
|
||||
'default_language' => setting('default_language'),
|
||||
'rotate_logs_after' => setting('rotate_logs_after'),
|
||||
'trial' => (bool)setting('trial'),
|
||||
'support' => (bool)setting('support'),
|
||||
'documentation' => (bool)setting('documentation'),
|
||||
'allow_registration' => (bool)setting('allow_registration'),
|
||||
'receive_email_on_server_creation' => (bool)setting('receive_email_on_server_creation'),
|
||||
'receive_email_on_site_creation' => (bool)setting('receive_email_on_site_creation'),
|
||||
'enable_api' => (bool)setting('enable_api'),
|
||||
'api_token' => setting('api_token'),
|
||||
'isolate_per_site_per_user' => (bool)setting('isolate_per_site_per_user'),
|
||||
'default_os' => setting('default_os', Server::OS_UBUNTU_22),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
Forms\Components\Grid::make(2)
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('Company name'))
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('email')
|
||||
->label(__('E-mail address'))
|
||||
->email(),
|
||||
Forms\Components\TextInput::make('support_emails')
|
||||
->label(__('Support email address'))
|
||||
->helperText('Separate by comma to allow more email addresses'),
|
||||
])
|
||||
->columnSpan(2),
|
||||
Forms\Components\Select::make('default_package')
|
||||
->options(fn () => Package::orderBy('name')->pluck('name', 'id'))
|
||||
->label(__('Select default package'))
|
||||
->helperText(__('Select the default package a user should get when you create or they register')),
|
||||
Forms\Components\Select::make('default_language')
|
||||
->options(collect(languages())->mapWithKeys(fn (string $language) => [$language => $language]))
|
||||
->label('Select default language')
|
||||
->helperText('Select the default language a user should get when you create or they register'),
|
||||
Forms\Components\FileUpload::make('logo')
|
||||
->label(__('Logo'))
|
||||
->disk('logos')
|
||||
->columnSpan(2),
|
||||
Forms\Components\Select::make('rotate_logs_after')
|
||||
->label(__('This will rotate any logs older than selected, this helps cleanup your database'))
|
||||
->options([
|
||||
null => __("Don't rotate logs"),
|
||||
'weeks-1' => __('Older than 1 week'),
|
||||
'months-1' => __('Older than 1 month'),
|
||||
'months-3' => __('Older than 3 months'),
|
||||
'months-6' => __('Older than 6 months'),
|
||||
'years-1' => __('Older than 1 year'),
|
||||
'years-2' => __('Older than 2 years'),
|
||||
'years-3' => __('Older than 3 years'),
|
||||
'years-4' => __('Older than 4 years'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Forms\Components\Select::make('default_os')
|
||||
->label(__('Select the default OS that should be used when users create a server'))
|
||||
->default(Server::OS_UBUNTU_22)
|
||||
->options([
|
||||
Server::OS_UBUNTU_18 => __('Ubuntu 18'),
|
||||
Server::OS_UBUNTU_20 => __('Ubuntu 20'),
|
||||
Server::OS_UBUNTU_22 => __('Ubuntu 22'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Forms\Components\Toggle::make('trial')
|
||||
->label(__('Enable trial'))
|
||||
->helperText(__('This will allow you to have users with trials.')),
|
||||
Forms\Components\Toggle::make('allow_registration')
|
||||
->label(__('Allow registration'))
|
||||
->helperText(__('Allow customer registration')),
|
||||
Forms\Components\Toggle::make('support')
|
||||
->label(__('Enable support platform'))
|
||||
->helperText(__('This will allow your customers to make support requests to you.')),
|
||||
Forms\Components\Toggle::make('documentation')
|
||||
->label(__('Enable documentation platform'))
|
||||
->helperText(__('This will allow you to create articles for your users to look at.')),
|
||||
Forms\Components\Toggle::make('receive_email_on_server_creation')
|
||||
->label(__('Receive email when customers create server'))
|
||||
->helperText(__('This will send an email to all admins notifying them about a new server installation.')),
|
||||
Forms\Components\Toggle::make('receive_email_on_site_creation')
|
||||
->label(__('Receive email when customers create site'))
|
||||
->helperText(__('This will send an email to all admins notifying them about a new site installation.')),
|
||||
Forms\Components\Toggle::make('enable_api')
|
||||
->label(__('Enable API'))
|
||||
->helperText(new HtmlString(__('This will allow you to interact with your system via the API. ') . '<a href="https://docs.ploi-core.io/304-core-api/737-introduction" target="_blank" class="text-primary-600">' . __('More information') . '</a>')),
|
||||
Forms\Components\TextInput::make('api_token')
|
||||
->label(__('API token'))
|
||||
->afterStateHydrated(function (?string $state, Forms\Components\TextInput $component) {
|
||||
$state = filled($state) ? decrypt($state) : null;
|
||||
|
||||
$component->state($state);
|
||||
})
|
||||
->dehydrateStateUsing(function (?string $state) {
|
||||
return filled($state) ? encrypt($state) : null;
|
||||
})
|
||||
->registerActions([
|
||||
'generate' => $generateAction = Action::make('generate')
|
||||
->label(__('Generate'))
|
||||
->icon('heroicon-o-key')
|
||||
->action(function (TextInput $component) {
|
||||
$component->state(Str::random(20));
|
||||
})
|
||||
->tooltip('Generate'),
|
||||
])
|
||||
->suffixAction($generateAction),
|
||||
Forms\Components\Toggle::make('isolate_per_site_per_user')
|
||||
->label(__('Enable site isolation per site & user'))
|
||||
->helperText(__('This will make sure each site created by one user is always isolated from another.')),
|
||||
]),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFormStatePath(): ?string
|
||||
{
|
||||
return 'data';
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$state = $this->form->getState();
|
||||
|
||||
$oldLogo = setting('logo');
|
||||
$oldDocumentation = setting('documentation');
|
||||
$oldSupport = setting('support');
|
||||
|
||||
if ($state['logo'] === null && $oldLogo) {
|
||||
Storage::disk('logos')->delete($oldLogo);
|
||||
}
|
||||
|
||||
setting($state);
|
||||
|
||||
cache()->forget('core.settings');
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title(__('Settings saved.'))
|
||||
->send();
|
||||
|
||||
if ($state['logo'] !== $oldLogo || $state['documentation'] !== $oldDocumentation || $state['support'] !== $oldSupport) {
|
||||
$this->redirect(Settings::getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
60
app/Filament/Pages/System.php
Normal file
60
app/Filament/Pages/System.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Pages\Page;
|
||||
use App\Services\VersionChecker;
|
||||
use Filament\Notifications\Notification;
|
||||
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||
|
||||
class System extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-adjustments-vertical';
|
||||
|
||||
protected static string $view = 'filament.pages.system';
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public function getCurrentVersion(): string
|
||||
{
|
||||
return app(VersionChecker::class)->getVersions()->currentVersion;
|
||||
}
|
||||
|
||||
public function getRemoteVersion(): string
|
||||
{
|
||||
return app(VersionChecker::class)->getVersions()->remoteVersion;
|
||||
}
|
||||
|
||||
public function refreshRemoteVersion(): void
|
||||
{
|
||||
app(VersionChecker::class)->flushVersionData();
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title(__('Refreshed versions'))
|
||||
->send();
|
||||
}
|
||||
|
||||
public function getHorizonWorkerStatus(): bool
|
||||
{
|
||||
return rescue(fn () => (bool)app(MasterSupervisorRepository::class)->all(), false, false);
|
||||
}
|
||||
|
||||
public function hasAvailableUpdate(): bool
|
||||
{
|
||||
return app(VersionChecker::class)->getVersions()->isOutOfDate();
|
||||
}
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
$systemChecker = app(VersionChecker::class);
|
||||
|
||||
if ($systemChecker->isOutOfDate()) {
|
||||
return 'Update available';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
93
app/Filament/Pages/Terms.php
Normal file
93
app/Filament/Pages/Terms.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Actions;
|
||||
use Filament\Pages\Page;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class Terms extends Page
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.terms';
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public array $data = [];
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
cache()->forget('core.settings');
|
||||
|
||||
$this->form->fill([
|
||||
'accept_terms_required' => (bool)setting('accept_terms_required'),
|
||||
'terms' => setting('terms'),
|
||||
'privacy' => setting('privacy'),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getFormSchema(): array
|
||||
{
|
||||
return [
|
||||
Forms\Components\Toggle::make('accept_terms_required')
|
||||
->label(__(' Require users to accept terms of service on registration'))
|
||||
->helperText(__('This will require newly registered users to accept the terms of service.')),
|
||||
Forms\Components\MarkdownEditor::make('terms')
|
||||
->label(__('Content Terms Of Service')),
|
||||
Forms\Components\MarkdownEditor::make('privacy')
|
||||
->label(__('Content Privacy Policy')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('load_terms_template')
|
||||
->label(__('Load Terms Of Service Template'))
|
||||
->action(function (self $livewire) {
|
||||
$template = Str::of(file_get_contents(storage_path('templates/terms-of-service.md')))
|
||||
->replace([
|
||||
'{NAME}',
|
||||
'{WEBSITE}',
|
||||
'{DATE}',
|
||||
], [
|
||||
setting('name'),
|
||||
config('app.url'),
|
||||
date('Y-m-d'),
|
||||
])
|
||||
->value();
|
||||
|
||||
$livewire->data['terms'] = $template;
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title(__('Loaded Terms Of Service Template'))
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFormStatePath(): ?string
|
||||
{
|
||||
return 'data';
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$state = $this->form->getState();
|
||||
|
||||
setting($state);
|
||||
|
||||
cache()->forget('core.settings');
|
||||
|
||||
Notification::make()
|
||||
->success()
|
||||
->title(__('Terms saved.'))
|
||||
->send();
|
||||
}
|
||||
}
|
||||
88
app/Filament/Resources/AlertResource.php
Normal file
88
app/Filament/Resources/AlertResource.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Alert;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
class AlertResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Alert::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-bell';
|
||||
|
||||
protected static ?string $navigationGroup = 'Settings';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'message';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\MarkdownEditor::make('message')
|
||||
->label(__('Content'))
|
||||
->columnSpan(2)
|
||||
->required(),
|
||||
Forms\Components\Select::make('type')
|
||||
->label(__('Type'))
|
||||
->options([
|
||||
Alert::TYPE_INFO => __('Informational'),
|
||||
Alert::TYPE_WARNING => __('Warning'),
|
||||
Alert::TYPE_DANGER => __('Danger'),
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\DateTimePicker::make('expires_at')
|
||||
->label(__('Expires at'))
|
||||
->seconds(false),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('message')
|
||||
->label(__('Content'))
|
||||
->formatStateUsing(fn (?string $state) => new HtmlString(Str::markdown($state))),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label(__('Type'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Alert::TYPE_INFO => __('Informational'),
|
||||
Alert::TYPE_WARNING => __('Warning'),
|
||||
Alert::TYPE_DANGER => __('Danger'),
|
||||
})
|
||||
->colors([
|
||||
'primary' => Alert::TYPE_INFO,
|
||||
'warning' => Alert::TYPE_WARNING,
|
||||
'danger' => Alert::TYPE_DANGER,
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('expires_at')
|
||||
->label('Expires')
|
||||
->default('-'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListAlerts::route('/'),
|
||||
'create' => Pages\CreateAlert::route('/create'),
|
||||
'edit' => Pages\EditAlert::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/AlertResource/Pages/CreateAlert.php
Normal file
11
app/Filament/Resources/AlertResource/Pages/CreateAlert.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
use App\Filament\Resources\AlertResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAlert extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AlertResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/AlertResource/Pages/EditAlert.php
Normal file
19
app/Filament/Resources/AlertResource/Pages/EditAlert.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\AlertResource;
|
||||
|
||||
class EditAlert extends EditRecord
|
||||
{
|
||||
protected static string $resource = AlertResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Filament/Resources/AlertResource/Pages/ListAlerts.php
Normal file
22
app/Filament/Resources/AlertResource/Pages/ListAlerts.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\AlertResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use App\Filament\Resources\AlertResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class ListAlerts extends ListRecords
|
||||
{
|
||||
protected static string $resource = AlertResource::class;
|
||||
|
||||
protected ?string $subheading = 'Alerts are meant to inform your users about things that are going on. For example server migrations, pricing changes. They will display as top-banner inside the panel.';
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
109
app/Filament/Resources/CertificateResource.php
Normal file
109
app/Filament/Resources/CertificateResource.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\Certificate;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\CertificateResource\Pages;
|
||||
|
||||
class CertificateResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Certificate::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-chat-bubble-bottom-center-text';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('site.name'),
|
||||
Forms\Components\TextInput::make('server_id'),
|
||||
Forms\Components\TextInput::make('status'),
|
||||
Forms\Components\TextInput::make('ploi_id'),
|
||||
Forms\Components\TextInput::make('domain'),
|
||||
Forms\Components\Textarea::make('certificate'),
|
||||
Forms\Components\Textarea::make('private'),
|
||||
Forms\Components\TextInput::make('type'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->searchable()
|
||||
->label(__('Server')),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->searchable()
|
||||
->label(__('Main domain')),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label('Type'),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Certificate::STATUS_BUSY => __('Busy'),
|
||||
Certificate::STATUS_ACTIVE => __('Active'),
|
||||
})
|
||||
->colors([
|
||||
'warning' => Certificate::STATUS_BUSY,
|
||||
'success' => Certificate::STATUS_ACTIVE,
|
||||
])
|
||||
->label(__('Status')),
|
||||
Tables\Columns\TextColumn::make('domain')
|
||||
->searchable()
|
||||
->wrap()
|
||||
->getStateUsing(function (Certificate $record) {
|
||||
$state = str($record->domain)->explode(',')->implode(', ');
|
||||
|
||||
return new HtmlString($state);
|
||||
})
|
||||
->label('Domains & aliases'),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->orderBy('domain');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCertificates::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CertificateResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\CertificateResource;
|
||||
|
||||
class ListCertificates extends ListRecords
|
||||
{
|
||||
protected static string $resource = CertificateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
86
app/Filament/Resources/CronjobResource.php
Normal file
86
app/Filament/Resources/CronjobResource.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Cronjob;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
class CronjobResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Cronjob::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-clock';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->searchable()
|
||||
->label(__('Site')),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Cronjob::STATUS_BUSY => __('Busy'),
|
||||
Cronjob::STATUS_ACTIVE => __('Active'),
|
||||
})
|
||||
->colors([
|
||||
'warning' => Cronjob::STATUS_BUSY,
|
||||
'success' => Cronjob::STATUS_ACTIVE,
|
||||
])
|
||||
->label(__('Status')),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->searchable()
|
||||
->label(__('Server')),
|
||||
Tables\Columns\TextColumn::make('command')
|
||||
->searchable()
|
||||
->label(__('Command')),
|
||||
Tables\Columns\TextColumn::make('frequency')
|
||||
->label(__('Frequency')),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListCronjobs::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
class CreateCronjob extends CreateRecord
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/CronjobResource/Pages/EditCronjob.php
Normal file
19
app/Filament/Resources/CronjobResource/Pages/EditCronjob.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
class EditCronjob extends EditRecord
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\CronjobResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
|
||||
class ListCronjobs extends ListRecords
|
||||
{
|
||||
protected static string $resource = CronjobResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Filament/Resources/DatabaseResource.php
Normal file
85
app/Filament/Resources/DatabaseResource.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Database;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
class DatabaseResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Database::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-circle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->label(__('Server'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->label(__('Site'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Database::STATUS_BUSY => __('Busy'),
|
||||
Database::STATUS_ACTIVE => __('Active'),
|
||||
})
|
||||
->colors([
|
||||
'warning' => Database::STATUS_BUSY,
|
||||
'success' => Database::STATUS_ACTIVE,
|
||||
])
|
||||
->label(__('Status')),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDatabases::route('/'),
|
||||
'edit' => Pages\EditDatabase::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
use App\Models\Database;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use App\Mail\Database\PasswordReset;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
|
||||
class EditDatabase extends Page
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected static string $resource = DatabaseResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.database-resource.pages.edit-database';
|
||||
|
||||
public Database $record;
|
||||
|
||||
protected ?string $recentlyUpdatedPassword = null;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->resetDatabasePasswordForm->fill();
|
||||
}
|
||||
|
||||
public function getForms(): array
|
||||
{
|
||||
return [
|
||||
'resetDatabasePasswordForm' => $this->makeForm()
|
||||
->schema([
|
||||
Toggle::make('send_new_password_to_user')
|
||||
->label(__('Email new password to user')),
|
||||
])
|
||||
->model($this->record),
|
||||
];
|
||||
}
|
||||
|
||||
public function resetDatabasePassword(): void
|
||||
{
|
||||
$state = $this->resetDatabasePasswordForm->getState();
|
||||
|
||||
$data = Ploi::make()
|
||||
->server($this->record->server->ploi_id)
|
||||
->databases($this->record->ploi_id)
|
||||
->users($this->record->users->first()->ploi_id)
|
||||
->resetPassword()
|
||||
->getData();
|
||||
|
||||
$this->recentlyUpdatedPassword = $data->new_password;
|
||||
|
||||
Notification::make()
|
||||
->title(__('Successfully reset database password.'))
|
||||
->success()
|
||||
->send();
|
||||
|
||||
if ($state['send_new_password_to_user']) {
|
||||
Mail::to($this->record->site->users)->send(new PasswordReset($this->record, $this->recentlyUpdatedPassword));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DatabaseResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
|
||||
class ListDatabases extends ListRecords
|
||||
{
|
||||
protected static string $resource = DatabaseResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
85
app/Filament/Resources/DocumentationCategoryResource.php
Normal file
85
app/Filament/Resources/DocumentationCategoryResource.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Str;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use App\Models\DocumentationCategory;
|
||||
use App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
use App\Filament\Resources\DocumentationCategoryResource\RelationManagers;
|
||||
|
||||
class DocumentationCategoryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = DocumentationCategory::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-tag';
|
||||
|
||||
protected static ?string $navigationGroup = 'Documentation';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $pluralLabel = 'Categories';
|
||||
|
||||
protected static ?string $label = 'Category';
|
||||
|
||||
public static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool)setting('documentation');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label(__('Title'))
|
||||
->unique(table: DocumentationCategory::class, column: 'title', ignoreRecord: true)
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
Forms\Components\MarkdownEditor::make('description')
|
||||
->label(__('Description'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable()
|
||||
->label(__('Title')),
|
||||
Tables\Columns\TextColumn::make('description')
|
||||
->label(__('Description'))
|
||||
->formatStateUsing(fn (string $state) => new HtmlString(Str::markdown($state))),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\DocumentationItemsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDocumentationCategories::route('/'),
|
||||
'create' => Pages\CreateDocumentationCategory::route('/create'),
|
||||
'edit' => Pages\EditDocumentationCategory::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['title'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
class CreateDocumentationCategory extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
class EditDocumentationCategory extends EditRecord
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DocumentationCategoryResource;
|
||||
|
||||
class ListDocumentationCategories extends ListRecords
|
||||
{
|
||||
protected static string $resource = DocumentationCategoryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationCategoryResource\RelationManagers;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class DocumentationItemsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'items';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
protected static ?string $label = 'Article';
|
||||
|
||||
protected static ?string $pluralLabel = 'Articles';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')
|
||||
->required()
|
||||
->maxLength(255),
|
||||
]);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->headerActions([
|
||||
Tables\Actions\CreateAction::make(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
71
app/Filament/Resources/DocumentationItemResource.php
Normal file
71
app/Filament/Resources/DocumentationItemResource.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Models\DocumentationItem;
|
||||
use App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
class DocumentationItemResource extends Resource
|
||||
{
|
||||
protected static ?string $model = DocumentationItem::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-duplicate';
|
||||
|
||||
protected static ?string $navigationGroup = 'Documentation';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $pluralLabel = 'Articles';
|
||||
|
||||
protected static ?string $label = 'Article';
|
||||
|
||||
public static function shouldRegisterNavigation(): bool
|
||||
{
|
||||
return (bool)setting('documentation');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('title')
|
||||
->label(__('Title'))
|
||||
->required(),
|
||||
Forms\Components\Select::make('documentation_category_id')
|
||||
->relationship('category', 'title')
|
||||
->searchable()
|
||||
->preload(),
|
||||
Forms\Components\MarkdownEditor::make('content')
|
||||
->label(__('Content'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('category.title')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListDocumentationItems::route('/'),
|
||||
'create' => Pages\CreateDocumentationItem::route('/create'),
|
||||
'edit' => Pages\EditDocumentationItem::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
class CreateDocumentationItem extends CreateRecord
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
class EditDocumentationItem extends EditRecord
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\DocumentationItemResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\DocumentationItemResource;
|
||||
|
||||
class ListDocumentationItems extends ListRecords
|
||||
{
|
||||
protected static string $resource = DocumentationItemResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
256
app/Filament/Resources/PackageResource.php
Normal file
256
app/Filament/Resources/PackageResource.php
Normal file
@@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\PackageResource\Pages;
|
||||
use App\Filament\Resources\PackageResource\RelationManagers;
|
||||
use App\Models\Package;
|
||||
use App\Models\Provider;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\HtmlString;
|
||||
|
||||
class PackageResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Package::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-swatch';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('Name'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('maximum_sites')
|
||||
->helperText(__('Set to 0 for unlimited'))
|
||||
->integer()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('maximum_servers')
|
||||
->helperText(__('Set to 0 for unlimited'))
|
||||
->integer()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('stripe_plan_id')
|
||||
->helperText(new HtmlString(__('Enter the pricing ID from Stripe here') . ' - <a href="https://docs.ploi-core.io/263-digging-deeper/743-using-stripe" target="ploi-docs-stripe" class="text-primary-500">How does this work?</a>'))
|
||||
->label(__('Stripe ID'))
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('price_monthly')
|
||||
->label(__('Monthly price'))
|
||||
->helperText(__('Fill this in if you want it to be monthly payments'))
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('price_yearly')
|
||||
->label(__('Yearly price'))
|
||||
->helperText(__('Fill this in if you want it to be yearly payments'))
|
||||
->required(),
|
||||
Forms\Components\Select::make('currency')
|
||||
->label(__('Currency'))
|
||||
->options([
|
||||
'usd' => 'USD $',
|
||||
'eur' => 'Euro €',
|
||||
'gbp' => 'GBP £',
|
||||
'nok' => 'NOK (Norwegian Krone)',
|
||||
'aud' => 'AUD (Australian dollar)',
|
||||
'cad' => 'CAD (Canadian dollar)',
|
||||
'inr' => 'INR (Indian ₹ rupee)',
|
||||
'thb' => 'THB (Thai Baht)',
|
||||
'brl' => 'BRL R$ (Brazilian Real)',
|
||||
'nz' => 'NZD $ (New Zealand Dollar)',
|
||||
])
|
||||
->required(),
|
||||
Forms\Components\Grid::make()
|
||||
->schema([
|
||||
Forms\Components\Section::make(__('Server permissions'))
|
||||
->icon(ServerResource::getNavigationIcon())
|
||||
->schema([
|
||||
Forms\Components\Checkbox::make('server_permissions.create')
|
||||
->reactive()
|
||||
->label('Allow server creation')
|
||||
->helperText('This will allow users to create servers'),
|
||||
Forms\Components\Checkbox::make('server_permissions.update')
|
||||
->label('Allow server updates')
|
||||
->helperText('This will allow users to update servers'),
|
||||
Forms\Components\Checkbox::make('server_permissions.delete')
|
||||
->label('Allow server deletion')
|
||||
->helperText('This will allow users to delete servers'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
Forms\Components\Section::make(__('Site permissions'))
|
||||
->icon(SiteResource::getNavigationIcon())
|
||||
->schema([
|
||||
Forms\Components\Checkbox::make('site_permissions.create')
|
||||
->label('Allow site creation')
|
||||
->helperText('This will allow users to create sites'),
|
||||
Forms\Components\Checkbox::make('site_permissions.update')
|
||||
->label('Allow site updates')
|
||||
->helperText('This will allow users to update sites'),
|
||||
Forms\Components\Checkbox::make('site_permissions.delete')
|
||||
->label('Allow site deletion')
|
||||
->helperText('This will allow users to delete sites'),
|
||||
])
|
||||
->columnSpan(1),
|
||||
]),
|
||||
|
||||
Forms\Components\Grid::make()
|
||||
->schema([
|
||||
Forms\Components\Section::make(__('Available server providers'))
|
||||
->description(__('These server providers will be available for users that are attached to this package.'))
|
||||
->icon(ProviderResource::getNavigationIcon())
|
||||
->schema([
|
||||
Forms\Components\CheckboxList::make('providers')
|
||||
->relationship('providers', 'name')
|
||||
->reactive(),
|
||||
Forms\Components\Grid::make(1)
|
||||
->schema([
|
||||
Forms\Components\Actions::make([
|
||||
Forms\Components\Actions\Action::make('manage_provider_plans')
|
||||
->label(__('Manage provider plans'))
|
||||
->icon('heroicon-o-adjustments-horizontal')
|
||||
->form(function (Package $record) {
|
||||
return $record->providers->sortBy('name')->map(function (Provider $provider) {
|
||||
return Forms\Components\Section::make($provider->label)
|
||||
->description(__('Select the plans that should be available for this provider on this package.'))
|
||||
->icon(ProviderResource::getNavigationIcon())
|
||||
->statePath($provider->id)
|
||||
->schema([
|
||||
Forms\Components\Toggle::make('select_specific_provider_plans')
|
||||
->label(__('Select subset'))
|
||||
->helperText(__('Check this box if you want to limit the provider plans available on this package.'))
|
||||
->default(false)
|
||||
->reactive()
|
||||
->afterStateUpdated(function (Forms\Components\Toggle $component, Forms\Set $set) use ($provider) {
|
||||
$set(
|
||||
path: "provider_plans",
|
||||
state: $component->getState() ? $provider->plans->pluck('id') : [],
|
||||
);
|
||||
}),
|
||||
Forms\Components\CheckboxList::make("provider_plans")
|
||||
->label(__('Select plans'))
|
||||
->options(fn() => $provider->plans->mapWithKeys(fn(ProviderPlan $providerPlan) => [$providerPlan->id => $providerPlan->label ?? $providerPlan->plan_id])->all())
|
||||
->visible(fn(Forms\Get $get) => $get('select_specific_provider_plans'))
|
||||
->reactive()
|
||||
->bulkToggleable()
|
||||
->columns(2)
|
||||
])
|
||||
->collapsible();
|
||||
})->all();
|
||||
})
|
||||
->fillForm(function (Package $record) {
|
||||
return $record->providers->mapWithKeys(function (Provider $provider) use ($record) {
|
||||
$providerPlanIds = $record->providerPlans()->whereBelongsTo($provider)->pluck('provider_plans.id');
|
||||
|
||||
return [$provider->id => [
|
||||
'select_specific_provider_plans' => $providerPlanIds->isNotEmpty(),
|
||||
'provider_plans' => $providerPlanIds->all(),
|
||||
]];
|
||||
})->all();
|
||||
})
|
||||
->action(function (Package $record, array $data) {
|
||||
$providerPlanIds = collect($data)
|
||||
// If `select_specific_provider_plans`, all provider plans are available. It could be that this
|
||||
// option was deselected, and that we have some left over provider plans in the field that
|
||||
// is now hidden. We will not include theSE IDs so that they ARE detached automatically.
|
||||
->where('select_specific_provider_plans', true)
|
||||
->pluck('provider_plans')
|
||||
->flatten();
|
||||
|
||||
// Detaches provider plans not specifically selected.
|
||||
$record->providerPlans()->sync($providerPlanIds);
|
||||
|
||||
Notification::make()
|
||||
->title(__('Provider plans saved'))
|
||||
->success()
|
||||
->send();
|
||||
})
|
||||
->modalSubmitActionLabel(__('Save'))
|
||||
->color('gray')
|
||||
->disabled(function (Package $record, Forms\Get $get) {
|
||||
$providers = collect($get('providers'))
|
||||
->map(fn(string $id): int => (int)$id)
|
||||
->sort();
|
||||
|
||||
return $record->providers->pluck('id')->map(fn(string $id): int => (int)$id)->sort()->toArray() !== $providers->all();
|
||||
})
|
||||
]),
|
||||
Forms\Components\Placeholder::make('save_warning')
|
||||
->content(__('You\'ve changed the available server providers. Please save your changes before you can manage the provider plans.'))
|
||||
->visible(function (Package $record, Forms\Get $get) {
|
||||
$providers = collect($get('providers'))
|
||||
->map(fn(string $id): int => (int)$id)
|
||||
->sort();
|
||||
|
||||
return $record->providers->pluck('id')->map(fn(string $id): int => (int)$id)->sort()->toArray() !== $providers->all();
|
||||
})
|
||||
->hiddenLabel(),
|
||||
])
|
||||
->hiddenOn('create'),
|
||||
])
|
||||
->columnSpan(1)
|
||||
])
|
||||
->visible(function ($get) {
|
||||
return $get('server_permissions')['create'];
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->description(function (Package $record) {
|
||||
if (!$record->stripe_plan_id) {
|
||||
return __('Not attached to Stripe.');
|
||||
}
|
||||
|
||||
return "Attached to stripe - {$record->price_monthly} {$record->currency}";
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('maximum_sites')
|
||||
->formatStateUsing(fn(int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->label(__('Maximum sites')),
|
||||
Tables\Columns\TextColumn::make('maximum_servers')
|
||||
->formatStateUsing(fn(int $state) => $state === 0 ? __('Unlimited') : $state)
|
||||
->label(__('Maximum servers')),
|
||||
Tables\Columns\TextColumn::make('users_count')
|
||||
->counts('users'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\UsersRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPackages::route('/'),
|
||||
'create' => Pages\CreatePackage::route('/create'),
|
||||
'edit' => Pages\EditPackage::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
class CreatePackage extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
}
|
||||
26
app/Filament/Resources/PackageResource/Pages/EditPackage.php
Normal file
26
app/Filament/Resources/PackageResource/Pages/EditPackage.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
class EditPackage extends EditRecord
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
public function afterSave(): void
|
||||
{
|
||||
// Necessary to refresh, in order to load the updated saved relationships and
|
||||
// correctly show or hide the "manage provider plans" warning placeholder.
|
||||
$this->getRecord()->refresh();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\PackageResource;
|
||||
|
||||
class ListPackages extends ListRecords
|
||||
{
|
||||
protected static string $resource = PackageResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PackageResource\RelationManagers;
|
||||
|
||||
use App\Models\User;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class UsersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'users';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->headerActions([
|
||||
...$table->getHeaderActions(),
|
||||
Action::make('add_user')
|
||||
->label(__('Add user'))
|
||||
->form(fn (self $livewire) => [
|
||||
Select::make('user_id')
|
||||
->label('User')
|
||||
->options(User::orderBy('name')->get()->mapWithKeys(fn (User $user) => [$user->id => $user->name]))
|
||||
->preload()
|
||||
->searchable()
|
||||
->required(),
|
||||
])
|
||||
->action(function (array $data, self $livewire) {
|
||||
$user = User::find($data['user_id']);
|
||||
|
||||
$user->update([
|
||||
'package_id' => $livewire->ownerRecord->id,
|
||||
]);
|
||||
})
|
||||
->button(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
80
app/Filament/Resources/ProviderPlanResource.php
Normal file
80
app/Filament/Resources/ProviderPlanResource.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\ProviderPlanResource\Pages;
|
||||
|
||||
class ProviderPlanResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ProviderPlan::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cube';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('label'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('provider.name')
|
||||
->label(__('Provider'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('plan_id')
|
||||
->label(__('Plan ID'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('label')
|
||||
->label(__('Label'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('provider_id')
|
||||
->label(__('Provider'))
|
||||
->options(fn () => Provider::orderBy('name')->get()->mapWithKeys(fn (Provider $provider) => [$provider->id => $provider->name])),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProviderPlans::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderPlanResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderPlanResource;
|
||||
|
||||
class ListProviderPlans extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProviderPlanResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
74
app/Filament/Resources/ProviderRegionResource.php
Normal file
74
app/Filament/Resources/ProviderRegionResource.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\ProviderRegion;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\ProviderRegionResource\Pages;
|
||||
|
||||
class ProviderRegionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ProviderRegion::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-globe-americas';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('provider.name')
|
||||
->label(__('Provider'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('region_id')
|
||||
->searchable()
|
||||
->label(__('Region')),
|
||||
Tables\Columns\TextColumn::make('label')
|
||||
->searchable()
|
||||
->label(__('Label')),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('provider_id')
|
||||
->label(__('Provider'))
|
||||
->options(fn () => Provider::orderBy('name')->pluck('name', 'id'))
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProviderRegions::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderRegionResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderRegionResource;
|
||||
|
||||
class ListProviderRegions extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProviderRegionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
120
app/Filament/Resources/ProviderResource.php
Normal file
120
app/Filament/Resources/ProviderResource.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Provider;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\ProviderPlan;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Filament\Resources\ProviderResource\Pages;
|
||||
use App\Actions\Provider\SynchronizeProviderAction;
|
||||
use App\Filament\Resources\ProviderResource\Widgets\AvailableProvidersOverview;
|
||||
|
||||
class ProviderResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Provider::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-cloud-arrow-up';
|
||||
|
||||
protected static ?string $navigationGroup = 'Providers';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label(__('Name'))
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
Forms\Components\CheckboxList::make('allowed_plans')
|
||||
->options(function (Provider $record) {
|
||||
return $record->plans->mapWithKeys(fn (ProviderPlan $plan) => [$plan->id => $plan->label ?? $plan->plan_id]);
|
||||
})
|
||||
->label(__('Allowed Plans')),
|
||||
Forms\Components\CheckboxList::make('allowed_regions')
|
||||
->options(fn (Provider $record) => $record->regions->pluck('label', 'id'))
|
||||
->label(__('Allowed Regions')),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id')
|
||||
->label('ID')
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->description(function (Provider $record) {
|
||||
return "{$record->plans_count} plan(s) · {$record->regions_count} region(s)";
|
||||
})
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('label')
|
||||
->label(__('Label'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('synchronize_provider')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (Provider $record) {
|
||||
$provider = app(SynchronizeProviderAction::class)->execute($record->ploi_id);
|
||||
|
||||
Notification::make()
|
||||
->title(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withCount(['plans', 'regions']);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
AvailableProvidersOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProviders::route('/'),
|
||||
'synchronize' => Pages\SynchronizeProviders::route('/synchronize'),
|
||||
'edit' => Pages\EditProvider::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\ProviderResource;
|
||||
|
||||
class EditProvider extends EditRecord
|
||||
{
|
||||
protected static string $resource = ProviderResource::class;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ProviderResource;
|
||||
|
||||
class ListProviders extends ListRecords
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected static string $resource = ProviderResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('synchronize_providers')
|
||||
->label(__('Synchronize providers'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('gray')
|
||||
->url(ProviderResource::getUrl('synchronize')),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\Page;
|
||||
use App\Filament\Resources\ProviderResource;
|
||||
|
||||
class SynchronizeProviders extends Page
|
||||
{
|
||||
protected static string $resource = ProviderResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.provider-resource.pages.synchronize-providers';
|
||||
|
||||
protected static ?string $title = 'Synchronize providers';
|
||||
|
||||
protected function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
ProviderResource\Widgets\AvailableProvidersOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProviderResource\Widgets;
|
||||
|
||||
use App\Models\AvailableProvider;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Provider\SynchronizeProviderAction;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class AvailableProvidersOverview extends TableWidget
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected static ?string $heading = 'Available Providers';
|
||||
|
||||
protected function getTableDescription(): ?string
|
||||
{
|
||||
return 'These are all the providers available from your ploi.io account which you can synchronize to your Ploi Core installation.';
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder|Relation
|
||||
{
|
||||
return AvailableProvider::query();
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('name')
|
||||
->label(__('Name')),
|
||||
TextColumn::make('label')
|
||||
->label(__('Label')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTableActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_provider')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (AvailableProvider $record, self $livewire) {
|
||||
$provider = app(SynchronizeProviderAction::class)->execute($record->id);
|
||||
|
||||
$livewire->dispatch('$refresh');
|
||||
|
||||
Notification::make()
|
||||
->title(__('Provider :provider synchronized successfully.', ['provider' => $provider->name]))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
98
app/Filament/Resources/RedirectResource.php
Normal file
98
app/Filament/Resources/RedirectResource.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use Filament\Tables;
|
||||
use App\Models\Redirect;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\RedirectResource\Pages;
|
||||
|
||||
class RedirectResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Redirect::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-arrow-top-right-on-square';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('site_id'),
|
||||
Forms\Components\TextInput::make('server_id'),
|
||||
Forms\Components\TextInput::make('status'),
|
||||
Forms\Components\TextInput::make('ploi_id'),
|
||||
Forms\Components\TextInput::make('redirect_from'),
|
||||
Forms\Components\TextInput::make('redirect_to'),
|
||||
Forms\Components\TextInput::make('type'),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('redirect_from')
|
||||
->wrap()
|
||||
->label(__('Redirect from'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('redirect_to')
|
||||
->wrap()
|
||||
->label(__('Redirect to'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->label(__('Server'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->label(__('Site'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('type')
|
||||
->label(__('Type')),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Redirect::STATUS_BUSY => __('Busy'),
|
||||
Redirect::STATUS_ACTIVE => __('Active'),
|
||||
})
|
||||
->colors([
|
||||
'warning' => Redirect::STATUS_BUSY,
|
||||
'success' => Redirect::STATUS_ACTIVE,
|
||||
])
|
||||
->label(__('Status')),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->sortable()
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListRedirects::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\RedirectResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\RedirectResource;
|
||||
|
||||
class ListRedirects extends ListRecords
|
||||
{
|
||||
protected static string $resource = RedirectResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
146
app/Filament/Resources/ServerResource.php
Normal file
146
app/Filament/Resources/ServerResource.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use App\Models\Server;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Server\SynchronizeServerAction;
|
||||
use App\Filament\Resources\ServerResource\Pages;
|
||||
use App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
class ServerResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Server::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-server';
|
||||
|
||||
protected static ?string $navigationGroup = 'Server management';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['name', 'ip', 'internal_ip', 'id'];
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('name')
|
||||
->required()
|
||||
->label(__('Name'))
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('ip')
|
||||
->required()
|
||||
->label('IP address')
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('internal_ip')
|
||||
->required()
|
||||
->label('Internal IP address')
|
||||
->columnSpan(2),
|
||||
Forms\Components\TextInput::make('maximum_sites')
|
||||
->label(__('Maximum sites'))
|
||||
->integer()
|
||||
->required()
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label(__('Name'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->label(__('Status'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Server::STATUS_BUSY => __('Busy'),
|
||||
Server::STATUS_ACTIVE => __('Active'),
|
||||
})
|
||||
->colors([
|
||||
'warning' => Server::STATUS_BUSY,
|
||||
'success' => Server::STATUS_ACTIVE,
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('users')
|
||||
->label(__('Users'))
|
||||
->wrap()
|
||||
->formatStateUsing(function (Server $record) {
|
||||
$state = $record
|
||||
->users
|
||||
->map(function (User $user) {
|
||||
return '<a href="' . UserResource::getUrl('edit', ['record' => $user]) . '" class="text-primary-600" style="white-space: nowrap">' . $user->name . '</a>';
|
||||
})
|
||||
->implode(', ') ?: '-';
|
||||
|
||||
return new HtmlString($state);
|
||||
})
|
||||
->searchable(query: function (Builder $query, string $search) {
|
||||
return $query->whereHas('users', function (Builder $query) use ($search) {
|
||||
return $query
|
||||
->where('name', 'LIKE', "%{$search}%")
|
||||
->orWhere('email', 'LIKE', "%{$search}%");
|
||||
});
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('maximum_sites')
|
||||
->label(__('Max sites'))
|
||||
->formatStateUsing(fn (Server $record) => $record->maximum_sites . " (Current: {$record->sites_count})")
|
||||
->counts('sites'),
|
||||
Tables\Columns\TextColumn::make('ip')
|
||||
->label(__('IP')),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->dateTime(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('synchronize_server')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(fn (Server $record) => app(SynchronizeServerAction::class)->execute($record->ploi_id))
|
||||
->visible(fn (Server $record) => $record->status === Server::STATUS_ACTIVE),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with(['users:id,name'])
|
||||
->withCount(['sites']);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\UsersRelationManager::class,
|
||||
RelationManagers\SitesRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListServers::route('/'),
|
||||
'edit' => Pages\EditServer::route('/{record}/edit'),
|
||||
'synchronize' => Pages\SynchronizeServers::route('/synchronize'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/ServerResource/Pages/CreateServer.php
Normal file
11
app/Filament/Resources/ServerResource/Pages/CreateServer.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ServerResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateServer extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/ServerResource/Pages/EditServer.php
Normal file
19
app/Filament/Resources/ServerResource/Pages/EditServer.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
class EditServer extends EditRecord
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
24
app/Filament/Resources/ServerResource/Pages/ListServers.php
Normal file
24
app/Filament/Resources/ServerResource/Pages/ListServers.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
class ListServers extends ListRecords
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('synchronize_servers')
|
||||
->label(__('Synchronize servers'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('gray')
|
||||
->url(ServerResource::getUrl('synchronize')),
|
||||
...parent::getHeaderActions(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use Filament\Notifications\Notification;
|
||||
use App\Filament\Resources\ServerResource;
|
||||
|
||||
class SynchronizeServers extends Page
|
||||
{
|
||||
protected static string $resource = ServerResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.server-resource.pages.synchronize-servers';
|
||||
|
||||
protected static ?string $title = 'Synchronize servers';
|
||||
|
||||
protected function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
ServerResource\Widgets\AvailableServersOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('synchronize_servers')
|
||||
->label(__('Synchronize all servers'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Synchronize servers')
|
||||
->modalDescription('This will synchronize all the servers that are listed in the table, to your Ploi Core installation.')
|
||||
->action(function () {
|
||||
$availableServers = Ploi::make()->synchronize()->servers()->getData();
|
||||
|
||||
foreach ($availableServers as $availableServer) {
|
||||
Server::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $availableServer->id,
|
||||
], [
|
||||
'status' => $availableServer->status,
|
||||
'name' => $availableServer->name,
|
||||
'ip' => $availableServer->ip_address,
|
||||
'ssh_port' => $availableServer->ssh_port,
|
||||
'internal_ip' => $availableServer->internal_ip,
|
||||
'available_php_versions' => $availableServer->installed_php_versions,
|
||||
]);
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('Servers synchronized successfully.'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class SitesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'sites';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('Site');
|
||||
}
|
||||
|
||||
protected static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('Sites');
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return SiteResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return SiteResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\RelationManagers;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class UsersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'users';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('User');
|
||||
}
|
||||
|
||||
protected static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('Users');
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->headerActions([
|
||||
...$table->getHeaderActions(),
|
||||
Tables\Actions\AttachAction::make()
|
||||
->preloadRecordSelect(),
|
||||
])
|
||||
->actions([
|
||||
...$table->getActions(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServerResource\Widgets;
|
||||
|
||||
use App\Models\AvailableServer;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Server\SynchronizeServerAction;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class AvailableServersOverview extends TableWidget
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected static ?string $heading = 'Available servers';
|
||||
|
||||
protected function getTableQuery(): Builder|Relation
|
||||
{
|
||||
return AvailableServer::query();
|
||||
}
|
||||
|
||||
protected function getTableDescription(): ?string
|
||||
{
|
||||
return 'These are all the servers available from your ploi.io account which you can synchronize to your Ploi Core installation.';
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('name')->label(__('Name')),
|
||||
TextColumn::make('ip_address')->label(__('IP address')),
|
||||
TextColumn::make('sites_count')->label(__('Sites')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTableActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_server')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (AvailableServer $record) {
|
||||
app(SynchronizeServerAction::class)->execute($record->id);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
150
app/Filament/Resources/SiteResource.php
Normal file
150
app/Filament/Resources/SiteResource.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Forms;
|
||||
use App\Models\Site;
|
||||
use App\Models\User;
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Site\SynchronizeSiteAction;
|
||||
use App\Filament\Resources\SiteResource\Pages;
|
||||
use App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
class SiteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Site::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-code-bracket';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 0;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('Site');
|
||||
}
|
||||
|
||||
public static function getPluralLabel(): ?string
|
||||
{
|
||||
return __('Sites');
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\TextInput::make('domain')
|
||||
->label(__('Domain'))
|
||||
->required()
|
||||
->hostname()
|
||||
->unique(Site::class, column: 'domain', ignoreRecord: true)
|
||||
->columnSpan(2),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('domain')
|
||||
->description(function (Site $record) {
|
||||
return "PHP $record->php_version";
|
||||
})
|
||||
->label(__('Name'))
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('server.name')
|
||||
->label(__('Server'))
|
||||
->sortable()
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('status')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => match ($state) {
|
||||
Site::STATUS_BUSY => __('Busy'),
|
||||
Site::STATUS_ACTIVE => __('Active'),
|
||||
})
|
||||
->colors([
|
||||
'warning' => Site::STATUS_BUSY,
|
||||
'success' => Site::STATUS_ACTIVE,
|
||||
])
|
||||
->label(__('Status')),
|
||||
Tables\Columns\TextColumn::make('users')
|
||||
->label(__('Users'))
|
||||
->wrap()
|
||||
->formatStateUsing(function (Site $record) {
|
||||
$state = $record
|
||||
->users
|
||||
->map(function (User $user) {
|
||||
return '<a href="' . UserResource::getUrl('edit', ['record' => $user]) . '" class="text-primary-600" style="white-space: nowrap">' . $user->name . '</a>';
|
||||
})
|
||||
->implode(', ') ?: '-';
|
||||
|
||||
return new HtmlString($state);
|
||||
})
|
||||
->searchable(query: function (Builder $query, string $search) {
|
||||
return $query->whereHas('users', function (Builder $query) use ($search) {
|
||||
return $query
|
||||
->where('name', 'LIKE', "%{$search}%")
|
||||
->orWhere('email', 'LIKE', "%{$search}%");
|
||||
});
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\Action::make('synchronize_site')
|
||||
->label(__('Synchronize'))
|
||||
->tooltip(__('This will synchronize the latest data from this provider to your Ploi Core installation'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (Site $record) {
|
||||
app(SynchronizeSiteAction::class)->execute($record->server->ploi_id, $record->ploi_id);
|
||||
})
|
||||
->visible(fn (Site $record) => $record->status === Site::STATUS_ACTIVE),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
])
|
||||
->defaultSort('sites.created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->with(['users', 'server']);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
RelationManagers\UsersRelationManager::class,
|
||||
RelationManagers\CertificatesRelationManager::class,
|
||||
RelationManagers\CronjobsRelationManager::class,
|
||||
RelationManagers\RedirectsRelationManager::class,
|
||||
RelationManagers\SystemUsersRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSites::route('/'),
|
||||
'edit' => Pages\EditSite::route('/{record}/edit'),
|
||||
'synchronize' => Pages\SynchronizeSites::route('/synchronize'),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Filament/Resources/SiteResource/Pages/CreateSite.php
Normal file
11
app/Filament/Resources/SiteResource/Pages/CreateSite.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateSite extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
}
|
||||
19
app/Filament/Resources/SiteResource/Pages/EditSite.php
Normal file
19
app/Filament/Resources/SiteResource/Pages/EditSite.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditSite extends EditRecord
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
27
app/Filament/Resources/SiteResource/Pages/ListSites.php
Normal file
27
app/Filament/Resources/SiteResource/Pages/ListSites.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use App\Traits\HasPloi;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListSites extends ListRecords
|
||||
{
|
||||
use HasPloi;
|
||||
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('synchronize_sites')
|
||||
->label(__('Synchronize sites'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->color('gray')
|
||||
->url(SiteResource::getUrl('synchronize')),
|
||||
...parent::getHeaderActions()
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Pages;
|
||||
|
||||
use App\Models\Site;
|
||||
use Filament\Actions;
|
||||
use App\Models\Server;
|
||||
use App\Services\Ploi\Ploi;
|
||||
use Filament\Resources\Pages\Page;
|
||||
use App\Filament\Resources\SiteResource;
|
||||
use Filament\Notifications\Notification;
|
||||
|
||||
class SynchronizeSites extends Page
|
||||
{
|
||||
protected static string $resource = SiteResource::class;
|
||||
|
||||
protected static string $view = 'filament.resources.site-resource.pages.synchronize-sites';
|
||||
|
||||
public function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
SiteResource\Widgets\AvailableSitesOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('synchronize_sites')
|
||||
->label(__('Synchronize all sites'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->requiresConfirmation()
|
||||
->modalHeading('Synchronize sites')
|
||||
->modalDescription('This will synchronize all the sites that are listed in the table, to your Ploi Core installation.')
|
||||
->action(function () {
|
||||
$availableSites = Ploi::make()->synchronize()->sites()->getData();
|
||||
|
||||
foreach ($availableSites as $availableSite) {
|
||||
$server = Server::query()->where('ploi_id', $availableSite->server_id)->firstOrFail();
|
||||
|
||||
$site = Site::query()
|
||||
->updateOrCreate([
|
||||
'ploi_id' => $availableSite->id,
|
||||
], [
|
||||
'domain' => $availableSite->domain,
|
||||
'php_version' => $availableSite->php_version,
|
||||
]);
|
||||
|
||||
$site->status = $availableSite->status;
|
||||
$site->server_id = $server->id;
|
||||
$site->save();
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('Sites synchronized successfully.'))
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\CertificateResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class CertificatesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'certificates';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'domain';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return CertificateResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return CertificateResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\CronjobResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class CronjobsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'cronjobs';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'command';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return CronjobResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return CronjobResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\DatabaseResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class DatabasesRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'databases';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return DatabaseResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return DatabaseResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\RedirectResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class RedirectsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'redirects';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'from';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return RedirectResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return RedirectResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\SiteSystemUserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class SystemUsersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'systemUsers';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'user_name';
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return SiteSystemUserResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return SiteSystemUserResource::table($table);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\RelationManagers;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
|
||||
class UsersRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'users';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getLabel(): ?string
|
||||
{
|
||||
return __('User');
|
||||
}
|
||||
|
||||
protected static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('Users');
|
||||
}
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return UserResource::form($form);
|
||||
}
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return UserResource::table($table)
|
||||
->headerActions([
|
||||
...$table->getHeaderActions(),
|
||||
Tables\Actions\AttachAction::make()
|
||||
->preloadRecordSelect(),
|
||||
])
|
||||
->actions([
|
||||
...$table->getActions(),
|
||||
Tables\Actions\DetachAction::make(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteResource\Widgets;
|
||||
|
||||
use App\Models\AvailableSite;
|
||||
use Filament\Widgets\TableWidget;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Actions\Site\SynchronizeSiteAction;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class AvailableSitesOverview extends TableWidget
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
protected static ?string $heading = 'Available sites';
|
||||
|
||||
protected function getTableDescription(): ?string
|
||||
{
|
||||
return 'These are all the sites available from your ploi.io account which you can synchronize to your Ploi Core installation.';
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder|Relation
|
||||
{
|
||||
return AvailableSite::query();
|
||||
}
|
||||
|
||||
protected function getTableColumns(): array
|
||||
{
|
||||
return [
|
||||
TextColumn::make('domain')->label(__('Site')),
|
||||
TextColumn::make('system_user')->label(__('System user')),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getTableActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('synchronize_site')
|
||||
->label(__('Synchronize'))
|
||||
->icon('heroicon-o-arrow-path')
|
||||
->action(function (AvailableSite $record) {
|
||||
app(SynchronizeSiteAction::class)->execute(ploiServerId: $record->server_id, ploiSiteId: $record->id);
|
||||
}),
|
||||
];
|
||||
}
|
||||
}
|
||||
70
app/Filament/Resources/SiteSystemUserResource.php
Normal file
70
app/Filament/Resources/SiteSystemUserResource.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use App\Models\SiteSystemUser;
|
||||
use Filament\Resources\Resource;
|
||||
use App\Filament\Resources\SiteSystemUserResource\Pages;
|
||||
|
||||
class SiteSystemUserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SiteSystemUser::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-user-group';
|
||||
|
||||
protected static ?string $navigationGroup = 'Site management';
|
||||
|
||||
protected static ?int $navigationSort = 6;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('user_name')
|
||||
->label(__('Username'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('site.domain')
|
||||
->label(__('Site'))
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label(__('Date'))
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
//
|
||||
])
|
||||
->bulkActions([
|
||||
//
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSiteSystemUsers::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SiteSystemUserResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
use App\Filament\Resources\SiteSystemUserResource;
|
||||
|
||||
class ListSiteSystemUsers extends ListRecords
|
||||
{
|
||||
protected static string $resource = SiteSystemUserResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
82
app/Filament/Resources/SubscriptionResource.php
Normal file
82
app/Filament/Resources/SubscriptionResource.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use Filament\Tables;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Resources\Resource;
|
||||
use Laravel\Cashier\Subscription;
|
||||
use App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
class SubscriptionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Subscription::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-banknotes';
|
||||
|
||||
protected static ?int $navigationSort = 4;
|
||||
|
||||
public static function getSlug(): string
|
||||
{
|
||||
return 'subscriptions';
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('user.name')
|
||||
->searchable()
|
||||
->url(fn ($record) => UserResource::getUrl('edit', ['record' => $record])),
|
||||
Tables\Columns\TextColumn::make('stripe_id')->searchable(),
|
||||
Tables\Columns\TextColumn::make('stripe_plan')->searchable(),
|
||||
Tables\Columns\TextColumn::make('stripe_status')
|
||||
->label('Status')
|
||||
->badge()
|
||||
->colors([
|
||||
'success' => \Stripe\Subscription::STATUS_ACTIVE,
|
||||
'warning' => \Stripe\Subscription::STATUS_PAST_DUE,
|
||||
]),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->sortable()
|
||||
->dateTime()
|
||||
->label(__('Date'))
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListSubscriptions::route('/'),
|
||||
// 'create' => Pages\CreateSubscription::route('/create'),
|
||||
// 'edit' => Pages\EditSubscription::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use App\Filament\Resources\SubscriptionResource;
|
||||
|
||||
class CreateSubscription extends CreateRecord
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\SubscriptionResource\Pages;
|
||||
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use App\Filament\Resources\SubscriptionResource;
|
||||
|
||||
class EditSubscription extends EditRecord
|
||||
{
|
||||
protected static string $resource = SubscriptionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user