beebmx / kirby-db
Enable Kirby 3 & 4 database support for Illuminate\Database
Installs: 1 864
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 3
Forks: 4
Open Issues: 0
Type:kirby-plugin
Requires
- php: ^8.1
- getkirby/composer-installer: ^1.2
- illuminate/database: ^10.0|^11.0
- illuminate/hashing: ^10.0|^11.0
Requires (Dev)
- getkirby/cms: ^4.0
- laravel/pint: ^1.13
- phpunit/phpunit: ^10.1
- spatie/ray: ^1.34
README
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.
Installation
Installation with composer
composer require beebmx/kirby-db
Usage
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' => '' ] ], ];
Usage Query Builder
To use Query Builder:
use Beebmx\KirbyDB\DB; DB::table('users')->get();
All the documentation about Query Builder is in the official documentation.
Usage Eloquent ORM
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.
Options
The default values of the package are:
Driver Examples
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' => '', ], ], ];
Usage note
You can use Kirby Env to hide your credentials from your code.