Last active
February 23, 2016 18:30
-
-
Save jgrossi/63b9475099556087f857 to your computer and use it in GitHub Desktop.
How to use different connections with Corcel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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