Skip to content

Commit

Permalink
Merge pull request #35 from vormkracht10/feature/database-check
Browse files Browse the repository at this point in the history
add DatabaseCheck
  • Loading branch information
markvaneijk authored Sep 29, 2023
2 parents 7c28455 + 616ac69 commit 92f71f6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Checks/DatabaseCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Vormkracht10\LaravelOK\Checks;

use Illuminate\Support\Facades\DB;
use Vormkracht10\LaravelOK\Checks\Base\Check;
use Vormkracht10\LaravelOK\Checks\Base\Result;

class DatabaseCheck extends Check
{
protected string $connectionName;

public function onConnection(string $name): static
{
$this->connectionName = $name;

return $this;
}

public function run(): Result
{
$result = Result::new();

$connectionName = $this->connectionName ?? config('database.default');

try {
DB::connection($connectionName)->getPdo();
} catch (\Throwable) {
return $result->failed("Could not connect to database on connection [{$connectionName}]");
}

return $result->ok('Connected to database successfully');
}
}

0 comments on commit 92f71f6

Please sign in to comment.