2025-12-30 15:03:19 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
2026-01-06 13:26:40 +08:00
|
|
|
|
use Illuminate\Support\Facades\URL;
|
2026-01-15 13:15:18 +08:00
|
|
|
|
use Illuminate\Support\Facades\Route;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
|
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Register any application services.
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function register(): void
|
|
|
|
|
|
{
|
|
|
|
|
|
//
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function boot(): void
|
|
|
|
|
|
{
|
2026-02-02 14:39:13 +08:00
|
|
|
|
// 如果是在正式環境或 APP_URL 是 https,強制轉為 https
|
|
|
|
|
|
if ($this->app->environment('production') || str_contains(config('app.url'), 'https')) {
|
2026-01-06 13:21:31 +08:00
|
|
|
|
URL::forceScheme('https');
|
|
|
|
|
|
}
|
2026-01-13 17:21:36 +08:00
|
|
|
|
|
|
|
|
|
|
// 隱含授權:讓 "super-admin" 角色擁有所有權限
|
|
|
|
|
|
\Illuminate\Support\Facades\Gate::before(function ($user, $ability) {
|
|
|
|
|
|
return $user->hasRole('super-admin') ? true : null;
|
|
|
|
|
|
});
|
2026-01-15 13:15:18 +08:00
|
|
|
|
|
|
|
|
|
|
// 載入房東後台路由 (只在 central domain 可用)
|
|
|
|
|
|
$this->app->booted(function () {
|
|
|
|
|
|
if (file_exists(base_path('routes/landlord.php'))) {
|
|
|
|
|
|
Route::middleware('web')->group(base_path('routes/landlord.php'));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2025-12-30 15:03:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-15 13:15:18 +08:00
|
|
|
|
|