Skip to content

Instantly share code, notes, and snippets.

@einnar82
Last active January 2, 2020 05:57
Show Gist options
  • Save einnar82/02ca85513ccafb2bed6c01bea8f757d9 to your computer and use it in GitHub Desktop.
Save einnar82/02ca85513ccafb2bed6c01bea8f757d9 to your computer and use it in GitHub Desktop.
Eloquent from database to database (Single database instance) - Part 2
<?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