1. Go to this page and download the library: Download monicahq/laradb 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/ */
monicahq / laradb example snippets
// app/Providers/AppServiceProvider.php
use Illuminate\Support\Facades\Gate;
public function boot(): void
{
Gate::define('viewLaraDb', function ($user) {
return $user->is_admin; // whatever "may read the database" means here
});
}
use LaraDb\DriverFactory;
$pdo = new PDO('sqlite:database.sqlite');
$driver = DriverFactory::fromPdo($pdo);
foreach ($driver->listTables() as $table) {
echo $table->name, "\n";
}
$page = $driver->getRows('users', page: 2, perPage: 25);
// And the row a foreign key points at:
$account = $driver->getRows('accounts', 1, 25, new RowFilter('id', '3'));
// Reading
public function listTables(): array; // TableInfo[]
public function getColumns(string $table): array; // ColumnInfo[]
public function getRowCount(string $table, ?RowFilter $filter = null): int;
public function getRows(string $table, int $page, int $perPage, ?RowFilter $filter = null): TablePage;
public function name(): string;
// Describing — everything the chrome is built from
public function serverVersion(): ?string;
public function databaseName(): ?string; // the db name, or the sqlite file
public function sizeInBytes(): ?int;
public function indexCount(): ?int;
public function metadata(): array; // engine settings, in display order
public function getForeignKeys(string $table): array; // column => "table.column"
public function foreignKeyTargets(): array; // table => the columns keys point at
public function describe(): DatabaseInfo; // all of the above, gathered once
public function queryCount(): int;