PHP code example of lagdo / dbadmin-app
1. Go to this page and download the library: Download lagdo/dbadmin-app library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lagdo / dbadmin-app example snippets
'queries' => [
'record' => [
'builder' => [
'enabled' => true,
],
'editor' => [
'enabled' => true,
],
],
'admin' => [
'history' => [
'show' => true,
'distinct' => true,
'limit' => 10,
],
'favorite' => [
'show' => true,
'limit' => 10,
],
],
'audit' => [
'enabled' => true,
],
'database' => [
// Same as the "servers" items, but "name" is the database name.
'driver' => 'pgsql',
'host' => "env(LOGGING_DB_HOST)",
'port' => "env(LOGGING_DB_PORT)",
'username' => "env(LOGGING_DB_USERNAME)",
'password' => "env(LOGGING_DB_PASSWORD)",
'name' => 'auditdb',
],
],
'queries' => [
'audit' => [
'enabled' => true,
'users' => [
// The emails of users that are allowed to access the audit page.
'[email protected] ',
],
],
'database' => [
// Same as the "servers" items, but "name" is the database name.
'driver' => 'pgsql',
'host' => "env(LOGGING_DB_HOST)",
'port' => "env(LOGGING_DB_PORT)",
'username' => "env(LOGGING_DB_USERNAME)",
'password' => "env(LOGGING_DB_PASSWORD)",
'name' => 'auditdb',
],
],
'app' => [
// ...
'packages' => [
Lagdo\DbAdmin\Db\DbAdminPackage::class => [
// Read the database credentials with the custom config reader.
'config' => [
'reader' => CustomConfigReader::class,
],
// ...
],
Lagdo\DbAdmin\Db\DbAuditPackage::class => [
// Read the database credentials with the custom config reader.
'config' => [
'reader' => CustomConfigReader::class,
],
// ...
],
],
],
use Lagdo\DbAdmin\Db\Config\AuthInterface;
use Lagdo\DbAdmin\Db\Config\InfisicalConfigReader;
use function Jaxon\jaxon;
class AppServiceProvider extends ServiceProvider
{
/**
* @param string $prefix
* @param string $option
* @param AuthInterface $auth
*
* @return string
*/
private function getSecretKey(string $prefix, string $option, AuthInterface $auth): string
{
return "users.{$prefix}.{$option}";
}
/**
* Register any application services.
*/
public function register(): void
{
// Customize the provided Infisical config reader.
$this->app->singleton(InfisicalConfigReader::class, function() {
$reader = jaxon()->di()->g(InfisicalConfigReader::class);
return $reader->setSecretKeyBuilder($this->getSecretKey(...));
});
}
}
use Lagdo\DbAdmin\Db\Config\InfisicalConfigReader;
'app' => [
// ...
'packages' => [
Lagdo\DbAdmin\Db\DbAdminPackage::class => [
// Read the database credentials with the custom config reader.
'config' => [
'reader' => InfisicalConfigReader::class,
],
// ...
],
Lagdo\DbAdmin\Db\DbAuditPackage::class => [
// Read the database credentials with the custom config reader.
'config' => [
'reader' => InfisicalConfigReader::class,
],
// ...
],
],
],
use Illuminate\Support\Str;
use Jaxon\Storage\StorageManager;
use League\Flysystem\FilesystemException;
use League\Flysystem\UnableToReadFile;
use League\Flysystem\UnableToWriteFile;
use function Jaxon\storage;
function getExportPath(string $filename): string
{
return Str::slug(auth()->user()->email) . "/$filename";
}
return [
'app' => [
'storage' => [
'stores' => [
'exports' => [
'adapter' => 'local',
'dir' => "/path/to/exports",
],
],
],
'packages' => [
Lagdo\DbAdmin\Db\DbAdminPackage::class => [
'servers' => [
// The database servers
],
'export' => [
'writer' => function(string $content, string $filename): string {
try {
// Make a Filesystem object with the storage.exports options.
$storage = storage()->get('exports');
$storage->write(getExportPath($filename), "$content\n");
} catch (FilesystemException|UnableToWriteFile) {
return '';
}
// Return the link to the exported file.
return route('dbadmin.export', ['filename' => $filename], false);
},
'reader' => function(string $filename): string {
// The 'export' route calls this function.
try {
// Make a Filesystem object with the storage.exports options.
$storage = storage()->get('exports');
$filepath = getExportPath($filename);
return !$storage->fileExists($filepath) ?
"No file $filename found." : $storage->read($filepath);
} catch (FilesystemException|UnableToReadFile) {
return "No file $filename found.";
}
},
],
],
],
],
...
];
'app' => [
'storage' => [
'stores' => [
'uploads' => [
'adapter' => 'local',
'dir' => '/path/to/the/upload/dir',
],
],
],
'upload' => [
'enabled' => true,
'files' => [
'sql_files' => [
'storage' => 'uploads',
],
],
],
],