PHP code example of jsnlib / joomla_database_eloquent

1. Go to this page and download the library: Download jsnlib/joomla_database_eloquent 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/ */

    

jsnlib / joomla_database_eloquent example snippets


use Jsnlib\Joomla\Database\Eloquent\Helper;

$builder = DB::connection('mysql');
Helper::connectionEloquent($builder);
// OR
$builder = DB::connection('mysql_custom');
Helper::connectionEloquent($builder);

Helper::proccess(true, function () use ($param)
{
    // ...
});


use Jsnlib\Joomla\Database\Eloquent\Helper;
use Illuminate\Database\Capsule\Manager as DB;

$db = new DB;
 
$db->addConnection([
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'database'  => 'test',
    'username'  => 'root',
    'password'  => '',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
]);

$db->addConnection([
    //...
], "mysql_custom");
 
$db->setAsGlobal();
$db->bootEloquent();

// 連線一
$builder = DB::connection();
Helper::connectionEloquent($builder);
Helper::proccess(true, function ($builder) use ($param)
{
    //....
});

// 連線二
$builder = DB::connection('mysql_custom');
Helper::connectionEloquent($builder);
Helper::proccess(true, function ($builder) use ($param)
{
    //....
});