Skip to content

Instantly share code, notes, and snippets.

@jgrossi
Last active February 23, 2016 18:30
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jgrossi/63b9475099556087f857 to your computer and use it in GitHub Desktop.
How to use different connections with Corcel
<?php
// set your model file and tell it the connection name you're using in config/database.php
// file: app/Post.php
namespace App;
use Corcel\Post as Corcel;
class Post extends Corcel
{
protected $connection = 'wordpress';
}
// fetching data inside a route, for example
// file: app/Http/routes.php
Route::get('/', function() {
$posts = App\Post::all(); // using the 'wordpress' connection
// ...
});
// if you use Corcel\Post to fetch data it will use the default database connection
// file: app/Http/routes.php
Route::get('/', function() {
$posts = Corcel\Post::all(); // using the 'default' connection ('mysql' is the default for Laravel)
// ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment