Skip to content

Commit ea19241

Browse files
author
ahmadhussnain
committed
Custom trait URLScheme has been added
1 parent 50bf377 commit ea19241

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

app/Http/Traits/URLScheme.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Http\Traits;
4+
5+
use Illuminate\Support\Facades\App;
6+
use Illuminate\Support\Facades\URL;
7+
8+
trait URLScheme {
9+
10+
/**
11+
* This function will check if the app is running on the
12+
* local environment or production environment
13+
*
14+
* @return bool
15+
*/
16+
public function isSecureScheme(): bool
17+
{
18+
return App::environment('local') ? false : true;
19+
}
20+
21+
/**
22+
* This function will set the URL scheme based on the environment.
23+
*/
24+
public function checkURLScheme() {
25+
if (App::environment('local')) {
26+
URL::forceScheme('http');
27+
} else {
28+
URL::forceScheme('https');
29+
}
30+
}
31+
}

app/Providers/AppServiceProvider.php

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

33
namespace App\Providers;
44

5-
use Illuminate\Support\Facades\App;
6-
use Illuminate\Support\Facades\URL;
5+
use App\Http\Traits\URLScheme;
76
use Illuminate\Support\ServiceProvider;
87

98
class AppServiceProvider extends ServiceProvider
109
{
10+
use URLScheme;
1111
/**
1212
* Register any application services.
1313
*
@@ -25,10 +25,6 @@ public function register()
2525
*/
2626
public function boot()
2727
{
28-
if (App::Environment('local')) {
29-
URL::forceScheme('http');
30-
} else {
31-
URL::forceScheme('https');
32-
}
28+
$this->checkURLScheme();
3329
}
3430
}

0 commit comments

Comments
 (0)