configureRateLimiting(); $this->routes(function () { // @codeCoverageIgnoreStart 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')); // @codeCoverageIgnoreEnd }); Route::model('brand', Brand::class); Route::model('service', Service::class); Route::model('single_optin', SingleOptin::class); Route::model('question', Question::class); Route::model('answer', Answer::class); Route::model('customer', Customer::class); // * Api parameters Bind. Route::model('serviceQuestion', Question::class); Route::bind('serviceCustomer', function ($value) { // * Load brand /** @var \App\Models\Brand $brand */ $brand = app(Service::class)->brand; // ? Parameter is email if (strpos($value, '@') !== false) { $customer = Customer::whereHas('brands', function ($q) use ($brand) { $q->where('brands.id', '=', $brand->id); })->where('email', '=', $value)->firstOrFail(); } try { // ? Have we found a customer yet if (!isset($customer) or \get_class($customer) !== Customer::class) { // ? Parameter is hashcode $customer = CustomerInfo::whereHas('brand', function ($q) use ($brand) { $q->where('brands.id', '=', $brand->id); })->where('hashcode', $value) ->with('customer')->firstOrFail()->customer; } // * Load Customer Login and Info for this brand. /** @var \App\Models\Customer $customer */ return $customer->loadBrandData($brand); } catch (ModelNotFoundException $e) { // * Uniform Not found exception using model Customer. throw (new ModelNotFoundException())->setModel(Customer::class); } }); } /** * Configure the rate limiters for the application. * * @return void */ protected function configureRateLimiting() { RateLimiter::for('web', function (Request $request) { // @codeCoverageIgnoreStart return Limit::perMinute(25) ->by(optional($request->user())->id ?: app('clientIp')); // @codeCoverageIgnoreEnd }); // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass RateLimiter::for('api', function (Request $request) { return Limit::perMinute(config('api.apiRequestRatePerMinute', 100)) ->by(app('clientIp')); }); } }