PHP code example of bitolaco / silex-eloquent

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

    

bitolaco / silex-eloquent example snippets


$app = new Silex\Application;
$app->register(
	new \BitolaCo\Silex\CapsuleServiceProvider(),
	array( 
		 'capsule.connection' => array(
			'driver' => 'mysql',
			'host' => 'localhost',
			'database' => 'dbname',
			'username' => 'root',
			'password' => '',
			'charset' => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix' => '',
			'logging' => true, // Toggle query logging on this connection.
		)
	)
);



$app = new Silex\Application;
$app->register(
	new \BitolaCo\Silex\CapsuleServiceProvider(),
	array(
		// DB Connection: Multiple.
		'capsule.connections' => array(
			'default' => array(
				'driver' => 'mysql',
				'host' => 'localhost',
				'database' => 'dname1',
				'username' => 'root',
				'password' => '',
				'charset' => 'utf8',
				'collation' => 'utf8_unicode_ci',
				'prefix' => '',
				'logging' => false, // Toggle query logging on this connection.
			),
			'other' => array(
				'driver' => 'mysql',
				'host' => 'localhost',
				'database' => 'dbname2',
				'username' => 'root',
				'password' => '',
				'charset' => 'utf8',
				'collation' => 'utf8_unicode_ci',
				'prefix' => '',
				'logging' => true, // Toggle query logging on this connection.
			)
		)
	)
);

$app = new Silex\Application;
$app->register(
	new \BitolaCo\Silex\CapsuleServiceProvider(),
	array( 
		 'capsule.connection' => array(
			'driver' => 'mysql',
			'host' => 'localhost',
			'database' => 'dbname',
			'username' => 'root',
			'password' => '',
			'charset' => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix' => '',
			'logging' => true, // Toggle query logging on this connection.
		),
		 'capsule.cache' => array(
			'driver' => 'apc',
			'prefix' => 'laravel',
		),
	)
);

$app = new Silex\Application;
$app->register(
	new \BitolaCo\Silex\CapsuleServiceProvider(),
	array( 
		 'capsule.connection' => array(
			'driver' => 'mysql',
			'host' => 'localhost',
			'database' => 'dbname',
			'username' => 'root',
			'password' => '',
			'charset' => 'utf8',
			'collation' => 'utf8_unicode_ci',
			'prefix' => '',
			'logging' => true, // Toggle query logging on this connection.
		),
		 'capsule.cache' => array(
			 'driver' => 'file',
			'path' => '/path/to/cache',
			'connection' => null,
			'table' => 'cache',
			'prefix' => 'laravel'
		),
	)
);


 = new Silex\Application();
$app->register(new \BitolaCo\Silex\CapsuleServiceProvider(), array(
    'capsule.connection' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'database'  => 'test',
        'username'  => 'root',
        'password'  => '',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    )
));

$app['capsule'];

class Book extends Illuminate\Database\Eloquent\Model 
{
    protected $table = "books";
}

var_dump(Book::find(1));