Answer the question
In order to leave comments, you need to log in
How to correctly add date when migrating to Laravel?
Hello, I created a migration. In it I create the table and I write down the initial data.
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStocksTable extends Migration
{
public function up()
{
Schema::create('stocks', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_general_ci';
$table->increments('id');
$table->text('title');
$table->longText('content');
$table->timestamps();
});
DB::statement('INSERT INTO `stock` (`title`, `content`, `created_at`, `updated_at`) VALUES ('some title', 'some content', '2019-04-29 00:00:00', '2019-04-29 00:00:00')');
}
public function down()
{
Schema::dropIfExists('stocks');
}
}
Answer the question
In order to leave comments, you need to log in
Seeders
are used to record the initial data .
For dates you can use:
Schema::create('stocks', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->string('title');
$table->text('content');
$table->dateTime('date')->default(DB::raw('CURRENT_TIMESTAMP'));
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question