class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('email');
$table->string('password');
$table->timestamps();
});
}
class CreateUsersExtendedTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('mysql2')->create('users_extended', function(Blueprint $table ){
$table->integer('user_id')->unsigned();
$table->string('phone');
$table->foreign('user_id')->references('id')->on('tweets.users')->onDelete('cascade');
});
}
Above is how i created a users_extended table in different database. What i want is to to bind my User Model to two tables which are in two different databases (tweets.users
& tweets2.users_extended
).
I want it because when ever i call User::save()
It should enter records on both the related tables.
Currently I have to do this code for saving a user with extended information like phone:
public function store()
{
$validation = Validator::make(Input::all(), User::$registerationRules);
if($validation->fails())
{
return Redirect::back()->withInput()->withErrors($validation);
}
$user = new User();
$user->email = Input::get('email');
$user->password = Hash::make( Input::get('password') );
$user->save();
$userExtended = new UserExtended();
$userExtended->phone = Input::get('phone');
$userExtended->user()->associate($user);
$userExtended->save();
}
Please note that I am looking for a solution of having a single Model not Relationships.
I am new to MVC and as i have read blogs about it I didn't find a way to achieve this. May be someone here knows if there is any possibility.