Download the PHP package jwh315/laravel-capsule-wrapper without Composer

On this page you can find all versions of the php package jwh315/laravel-capsule-wrapper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-capsule-wrapper

laravel-capsule-wrapper

Use the Eloquent ORM outside of the Laravel Framework with an existing PDO database connection.

disclaimer

This project is currently a proof of concept, without tests. I have manually tested it using a few standard Laravel operations with success, but I cannot currently vouch for its robustness in a real world PHP application.

One of the main issues I have not fully fleshed out is the database name parameter that you would normally pass into an eloquent connection. I have chosen to omit this parameter as my use case requires a database connection, with the ability to access multiple databases on the same connection. From my limited testing, this hasn't posed a problem, but I could be missing something.

Lastly, this only works for Mysql currently. This is done in CapsuleManager\Wrapper\DatabaseManager::addDefaultConnection(), theoretically you should be able to swap out any of the other Illuminate\Database connection classes as needed.

installation

composer require jwh315/laravel-capsule-wrapper

usage

This is pretty much the same as the usage instructions on the Illuminate\Database repository. It should be noted that I have not tested the Schema Builder

use CapsuleManager\Wrapper\Manager;
use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;

$dsn = "mysql:host=" . DBHOST;
$pdo = new \PDO($dsn, DBUSER, DBPASS);

$capsule = new Manager($pdo);

// Set the event dispatcher used by Eloquent models... (optional)
$capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();

$t = $capsule::table('mysql.db')
             ->where('Host', 'localhost')
             ->get();

dd($t);

I also added a static accessor to encapsulate all of this boilerplate inside of the wrapper class, if you are going to use the defaults settings in the above example, this will also work.

use CapsuleManager\Wrapper\Manager as Capsule;

$dsn = "mysql:host=" . DBHOST;
$pdo = new \PDO($dsn, DBUSER, DBPASS);

$capsule = Capsule::init($pdo);

$t = $capsule::table('mysql.db')
             ->where('Host', 'localhost')
             ->get();

dd($t);

Using the Eloquent ORM

This is exactly the same as you would expect, except as mentioned above, I did not add a way to set the database name so you will have to set it explicitly

//initialize the capsule manager
use CapsuleManager\Wrapper\Manager as Capsule;

$dsn = "mysql:host=" . DBHOST;
$pdo = new \PDO($dsn, DBUSER, DBPASS);

$capsule = Capsule::init($pdo);

//user model example
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    //this needs to be set on all your models
    protected $table = 'test.users';
}

//using the user model
dd(User::all()->last()->login);

All versions of laravel-capsule-wrapper with dependencies

PHP Build Version
Package Version
Requires illuminate/database Version ^5.4
illuminate/events Version ^5.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jwh315/laravel-capsule-wrapper contains the following files

Loading the files please wait ....