Last active
January 2, 2020 05:57
-
-
Save einnar82/02ca85513ccafb2bed6c01bea8f757d9 to your computer and use it in GitHub Desktop.
Eloquent from database to database (Single database instance) - Part 2
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 | |
namespace App; | |
use Illuminate\Database\Eloquent\Model; | |
class Post extends Model | |
{ | |
protected $guarded = ['id']; | |
/** | |
* Eloquent grammars can read multiple schema relationships | |
* within the same database instance. | |
* | |
* Just like the regular mysql query, you can declare multiple database relationships | |
* override the $table to 'database-name.table_name' | |
* or defined the connection name via | |
* $connection = 'your_database_connection'; | |
* | |
*/ | |
// protected $table = 'eloquent-test2.posts'; | |
protected $connection = 'mysql2'; | |
public function user() | |
{ | |
return $this->belongsTo(User::class); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment