Skip to content

Commit 047b21f

Browse files
committed
Use Environment enum
1 parent 1024616 commit 047b21f

17 files changed

+88
-58
lines changed

app/Enums/Environment.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
use Illuminate\Support\Collection;
6+
7+
enum Environment: string
8+
{
9+
case LOCAL = 'local';
10+
case TESTING = 'testing';
11+
case PRODUCTION = 'production';
12+
case STAGING = 'staging';
13+
14+
public static function values(): Collection
15+
{
16+
return collect(self::cases())->map(fn ($case): string => $case->value);
17+
}
18+
}

app/Filament/Pages/Auth/Login.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Filament\Pages\Auth;
44

5+
use App\Enums\Environment;
56
use Filament\Pages\Auth\Login as BasePage;
67

78
class Login extends BasePage
@@ -10,7 +11,7 @@ public function mount(): void
1011
{
1112
parent::mount();
1213

13-
if (\app()->environment('local')) {
14+
if (\app()->environment(Environment::LOCAL->value)) {
1415
$this->form->fill([
1516
'email' => \config('app.seed.users.super.email'),
1617
'password' => \config('app.seed.users.super.password'),

app/Http/Controllers/LoginController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Enums\Environment;
56
use App\Http\Requests\Login\LoginStoreRequest;
67
use Illuminate\Http\Request;
78
use Illuminate\Validation\ValidationException;
@@ -10,7 +11,7 @@ class LoginController extends Controller
1011
{
1112
public function show(Request $request)
1213
{
13-
return inertia('Login/Show', app()->environment('local', 'testing') ? [
14+
return inertia('Login/Show', app()->environment([Environment::LOCAL->value, Environment::TESTING->value]) ? [
1415
'email' => config('app.seed.users.super.email'),
1516
'password' => config('app.seed.users.super.password'),
1617
'remember' => true,

app/Http/Controllers/RegisterController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Enums\Environment;
56
use App\Enums\Role;
67
use App\Http\Requests\Register\RegisterStoreRequest;
78
use App\Models\User;
@@ -11,7 +12,7 @@ class RegisterController extends Controller
1112
{
1213
public function show()
1314
{
14-
return inertia('Register/Show', app()->environment('local', 'testing') ? [
15+
return inertia('Register/Show', app()->environment([Environment::LOCAL->value, Environment::TESTING->value]) ? [
1516
'first_name' => 'Jim',
1617
'last_name' => 'Gordon',
1718
'email' => 'test@test.com',

app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use App\Enums\Environment;
56
use App\Models\User;
67
use Illuminate\Http\Resources\Json\JsonResource;
78
use Illuminate\Support\Facades\Vite;
@@ -22,7 +23,7 @@ class AppServiceProvider extends ServiceProvider
2223
{
2324
public function register(): void
2425
{
25-
if ($this->app->environment('local')) {
26+
if ($this->app->environment(Environment::LOCAL->value)) {
2627
$this->app->register(\Laravel\Telescope\TelescopeServiceProvider::class);
2728
$this->app->register(TelescopeServiceProvider::class);
2829
}

app/Providers/Filament/AdminPanelProvider.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Providers\Filament;
44

55
use Althinect\FilamentSpatieRolesPermissions\FilamentSpatieRolesPermissionsPlugin;
6+
use App\Enums\Environment;
67
use App\Enums\Role;
78
use Filament\Http\Middleware\Authenticate;
89
use Filament\Http\Middleware\DisableBladeIconComponents;
@@ -42,16 +43,16 @@ public function panel(Panel $panel): Panel
4243
->plugins([
4344
FilamentSpatieRolesPermissionsPlugin::make(),
4445
EnvironmentIndicatorPlugin::make()
45-
->visible(fn () => \auth()->user()?->hasRole(Role::SUPER_ADMIN) && \app()->environment() !== 'production')
46+
->visible(fn () => \auth()->user()?->hasRole(Role::SUPER_ADMIN) && \app()->environment() !== Environment::PRODUCTION->value)
4647
->showBorder(false)
4748
->color(fn () => match (app()->environment()) {
48-
'production' => Color::Green,
49-
'staging' => Color::Blue,
50-
'local' => Color::Red,
49+
Environment::PRODUCTION->value => Color::Green,
50+
Environment::STAGING->value => Color::Blue,
51+
Environment::LOCAL->value => Color::Red,
5152
default => Color::Gray,
5253
}),
5354
DebuggerPlugin::make()
54-
->authorize(fn () => \auth()->user()?->hasRole(Role::SUPER_ADMIN) && \app()->environment() !== 'production'),
55+
->authorize(fn () => \auth()->user()?->hasRole(Role::SUPER_ADMIN) && \app()->environment() !== Environment::PRODUCTION->value),
5556
])
5657
->middleware([
5758
EncryptCookies::class,

app/Providers/TelescopeServiceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use App\Enums\Environment;
56
use Illuminate\Support\Facades\Gate;
67
use Laravel\Telescope\IncomingEntry;
78
use Laravel\Telescope\Telescope;
@@ -18,7 +19,7 @@ public function register(): void
1819

1920
$this->hideSensitiveRequestDetails();
2021

21-
$isLocal = $this->app->environment('local');
22+
$isLocal = $this->app->environment(Environment::LOCAL->value);
2223

2324
Telescope::filter(function (IncomingEntry $entry) use ($isLocal) {
2425
return $isLocal ||
@@ -35,7 +36,7 @@ public function register(): void
3536
*/
3637
protected function hideSensitiveRequestDetails(): void
3738
{
38-
if ($this->app->environment('local')) {
39+
if ($this->app->environment(Environment::LOCAL->value)) {
3940
return;
4041
}
4142

config/app.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use App\Enums\Environment;
4+
35
return [
46

57
'seed' => [
@@ -43,7 +45,7 @@
4345
|
4446
*/
4547

46-
'env' => env('APP_ENV', 'production'),
48+
'env' => env('APP_ENV', Environment::PRODUCTION->value),
4749

4850
/*
4951
|--------------------------------------------------------------------------

config/horizon.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Enums\Environment;
34
use Illuminate\Support\Str;
45

56
return [
@@ -198,23 +199,23 @@
198199
],
199200

200201
'environments' => [
201-
'production' => [
202+
Environment::PRODUCTION->value => [
202203
'supervisor-1' => [
203204
'maxProcesses' => 10,
204205
'balanceMaxShift' => 1,
205206
'balanceCooldown' => 3,
206207
],
207208
],
208209

209-
'staging' => [
210+
Environment::STAGING->value => [
210211
'supervisor-1' => [
211212
'maxProcesses' => 5,
212213
'balanceMaxShift' => 1,
213214
'balanceCooldown' => 3,
214215
],
215216
],
216217

217-
'local' => [
218+
Environment::LOCAL->value => [
218219
'supervisor-1' => [
219220
'maxProcesses' => 3,
220221
],

config/permission.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
/*
7676
* Change this if you want to name the related pivots other than defaults
7777
*/
78-
'role_pivot_key' => null, //default 'role_id',
79-
'permission_pivot_key' => null, //default 'permission_id',
78+
'role_pivot_key' => null, // default 'role_id',
79+
'permission_pivot_key' => null, // default 'permission_id',
8080

8181
/*
8282
* Change this if you want to name the related model primary key other than

0 commit comments

Comments
 (0)