ldc-crm/app/Providers/RouteServiceProvider.php

58 lines
1.7 KiB
PHP
Raw Normal View History

2020-12-01 17:02:10 +01:00
<?php
namespace App\Providers;
2021-07-22 15:14:07 +02:00
use App\Models\Brand;
2021-03-14 10:45:42 +01:00
use App\Models\Customer;
2020-12-01 17:02:10 +01:00
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/customers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
2021-03-14 10:45:42 +01:00
Route::prefix('api')->middleware('api')->namespace($this->namespace)->group(base_path('routes/api.php'));
Route::middleware('web')->namespace($this->namespace)->group(base_path('routes/web.php'));
});
2021-03-14 10:45:42 +01:00
Route::bind('customer', function ($value) {
return Customer::whereHas('infos', function ($q) use ($value) {
$q->where('customer_infos.hashcode', $value);
})->first() ?? (\ctype_digit($value) ? Customer::where('id', '=', $value)->first() : null) ??
Customer::where('email', '=', $value)->firstOrFail();
2020-12-01 17:02:10 +01:00
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(config('api.apiRequestRatePerMinute'))->by(optional($request->user())->id ?: $request->ip());
2020-12-01 17:02:10 +01:00
});
}
}