Last active
January 9, 2020 07:07
-
-
Save einnar82/e3df19bf45f4cdce609280346024c86f to your computer and use it in GitHub Desktop.
Eloquent from database to database (Single database instance) - Part 4
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 | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class CreatePostsTable extends Migration | |
{ | |
/** | |
* The database schema. | |
* | |
* @var \Illuminate\Database\Schema\Builder | |
*/ | |
protected $schema; | |
/** | |
* Create a new migration instance. | |
* | |
* @return void | |
*/ | |
public function __construct() | |
{ | |
$this->schema = Schema::connection($this->getConnection()); | |
} | |
/** | |
* Get the migration connection name. | |
* | |
* @return string|null | |
*/ | |
public function getConnection() | |
{ | |
return 'mysql2'; | |
} | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
$this->schema->create('posts', function (Blueprint $table) { | |
$table->bigIncrements('id'); | |
$table->integer('user_id')->default(1); | |
$table->longText('content')->nullable(); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
$this->schema->dropIfExists('posts'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment