Skip to content

Commit

Permalink
bug fix after boot package
Browse files Browse the repository at this point in the history
  • Loading branch information
MajidMohammadian committed Aug 5, 2024
1 parent 7f10276 commit 45df919
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/BanIpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace JobMetric\BanIp;

use JobMetric\BanIp\Facades\BanIp as BanIpFacade;
use JobMetric\BanIp\Models\BanIp as BanIpModels;
use JobMetric\PackageCore\Exceptions\ConsoleKernelFileNotFoundException;
use JobMetric\PackageCore\Exceptions\MigrationFolderNotFoundException;
use JobMetric\PackageCore\Exceptions\RegisterClassTypeNotFoundException;
use JobMetric\PackageCore\Exceptions\ViewFolderNotFoundException;
use JobMetric\PackageCore\PackageCore;
use JobMetric\PackageCore\PackageCoreServiceProvider;
use Throwable;

class BanIpServiceProvider extends PackageCoreServiceProvider
{
Expand All @@ -33,13 +34,19 @@ public function configuration(PackageCore $package): void
->registerClass('BanIp', BanIp::class);
}

/**
* after boot package
*
* @return void
* @throws Throwable
*/
public function afterBootPackage(): void
{
if (checkDatabaseConnection() && !app()->runningInConsole() && !app()->runningUnitTests()) {
$result = BanIpFacade::all([
['ip', request()->ip()],
['expired_at', '>', now()->format('Y-m-d H:i:s')]
]);
$result = BanIpModels::query()
->where('ip', '=', request()->ip())
->where('expired_at', '>', now()->format('Y-m-d H:i:s'))
->get();

if ($result->count()) {
$banIp = $result->first();
Expand Down

0 comments on commit 45df919

Please sign in to comment.