Files
mytodos/app/Providers/AppServiceProvider.php
T
ecdown 177f122c10
tests / ci (push) Canceled after 0s
added roles and organizations
2026-10-15 20:59:32 -07:00

90 lines
2.3 KiB
PHP

<?php
namespace App\Providers;
use App\Http\Responses\RegisterResponse;
use App\Models\Organization;
use App\Models\User;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Illuminate\Validation\Rules\Password;
use Laravel\Cashier\Cashier;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
$this->registerFortifyResponses();
}
/**
* Swap Fortify's registration response for one that starts checkout for the
* plan the account signed up with.
*/
protected function registerFortifyResponses(): void
{
$this->app->singleton(
RegisterResponseContract::class,
RegisterResponse::class,
);
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
$this->configureDefaults();
$this->configureCashier();
$this->defineGates();
}
/**
* Define the site-wide administrator ability. This is deliberately separate
* from an organization's Owner/Admin roles, which only ever grant rights
* inside a single workspace.
*/
protected function defineGates(): void
{
Gate::define('accessAdmin', fn (User $user): bool => $user->isSiteAdmin());
}
/**
* Make organizations, rather than users, the Stripe customer. This also
* determines the foreign key Cashier uses on the subscriptions table.
*/
protected function configureCashier(): void
{
Cashier::useCustomerModel(Organization::class);
}
/**
* Configure default behaviors for production-ready applications.
*/
protected function configureDefaults(): void
{
Date::use(CarbonImmutable::class);
DB::prohibitDestructiveCommands(
app()->isProduction(),
);
Password::defaults(fn (): ?Password => app()->isProduction()
? Password::min(12)
->mixedCase()
->letters()
->numbers()
->symbols()
->uncompromised()
: null,
);
}
}