Kirby DB use Laravel illuminate/database
package and enable their features for Kirby.
This package enable Laravel Query Builder, Laravel Eloquent ORM and Laravel Schema for your own Kirby applications.
composer require beebmx/kirby-db
First you need to set your database in your config/config.php
file:
<?php
return [
'beebmx.kirby-db.drivers' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => 'storage/database/database.sqlite',
'prefix' => ''
]
],
];
To use Query Builder:
use Beebmx\KirbyDB\DB;
DB::table('users')->get();
All the documentation about Query Builder is in the official documentation.
To use Eloquent ORM, first you need to create a Model
:
use Beebmx\KirbyDB\Model;
class User extends Model {
}
Then you can use your new model with:
\User::all();
All the documentation about Eloquent ORM is in the official documentation.
The default values of the package are:
Option | Default | Values | Description |
---|---|---|---|
beebmx.kirby-db.default | sqlite | mysql / sqlite / pgsql / sqlsrv |
Default driver |
beebmx.kirby-db.drivers | [] | (array) | Array with all the drivers available |
beebmx.kirby-db.eloquent | false | true / false |
Enable Eloquent ORM |
This is an example of the drivers available:
return [
'beebmx.kirby-db.drivers' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => 'storage/database/database.sqlite',
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'port' => '3306',
'database' => 'database',
'username' => 'user',
'password' => '',
'unix_socket' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => '127.0.0.1',
'port' => '5432',
'database' => 'database',
'username' => 'user',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
'sslmode' => 'prefer',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'localhost',
'port' => '1433',
'database' => 'database',
'username' => 'user',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
],
],
];
You can use Kirby Env to hide your credentials from your code.