Initial Laravel 12 starter kit

This commit is contained in:
zino
2025-11-16 00:01:06 +01:00
parent 98c77c7df6
commit 7fa25fc80c
63 changed files with 15204 additions and 1 deletions

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
/**
* Register any application services.
*/
public function register(): void {
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void {
// Prevents lazy loading
// Prevents silently discarding attributes.
// Prevents accessing missing attributes.
Model::shouldBeStrict();
// Automatically eager-load needed relations.
Model::automaticallyEagerLoadRelationships();
// Force HTTPS for all generated URLs.
URL::forceHttps(
$this->app->environment(['production']),
);
// Prohibits: db:wipe, migrate:fresh, migrate:refresh, and migrate:reset
DB::prohibitDestructiveCommands($this->app->environment(['production']));
// Prefetch all assets at once.
Vite::prefetch();
// Disable resourc wrapping
JsonResource::withoutWrapping();
// Globally rate limit api requests
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(500)
->by($request->user()->id ?? $request->ip())
->response(function () {
return response()->json([
'message' => 'Too many attempts. Try again later.',
], 429);
});
});
}
}