Consolidate service providers

This commit is contained in:
Shift
2024-03-18 16:13:28 +00:00
parent 31d13cb013
commit 11b63e791f
4 changed files with 44 additions and 70 deletions

View File

@@ -2,11 +2,27 @@
namespace App\Providers;
use App\Models\User;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Spatie\Sheets\Sheets;
use URL;
class AppServiceProvider extends ServiceProvider
{
/**
* The path to your application's "home" route.
*
* Typically, users are redirected here after authentication.
*
* @var string
*/
public const HOME = '/home';
/**
* Register any application services.
*/
@@ -23,5 +39,31 @@ class AppServiceProvider extends ServiceProvider
if (config('app.env') === 'production') {
URL::forceScheme('https');
}
$this->bootAuth();
$this->bootRoute();
}
public function bootAuth(): void
{
Gate::define('viewPulse', function (User $user) {
return $user->admin;
});
}
public function bootRoute(): void
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
Route::bind('post', function ($path) {
return $this->app->make(Sheets::class)
->collection('posts')
->get($path) ?? abort(404);
});
}
}