How to add the date when migrating to Laravel?

Hello, I created a migration. In it create a table and record 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');
}
}

do not specify id, the AutoNumber will be automatically populated if you do not specify a date after you will have to fill in manually.
Is it right to set the date in the migration line or you can fill it automatically with the date and time of migration?
March 20th 20 at 11:35
1 answer
March 20th 20 at 11:37
Solution
To record the initial data used by the seeders .
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'));
 });
Thanks for the tip about the seeder. Tried it, works perfectly and is very comfortable. - Marion91 commented on March 20th 20 at 11:40
Another came from.. don't even know what to call it.

@Brent_Cartwrig don't even think about. - Kevon.Barrows commented on March 20th 20 at 11:43
@Armand, what's wrong ? - enoch commented on March 20th 20 at 11:46
@Cleora51,
$table->engine = 'InnoDB';
 $table->charset = 'utf8';
 $table->collation = 'utf8_general_ci';

why? InnoDB the default, utf8 is used not only utf8mb4.
$table->dateTime('date')
at lark have created_at and updated_at, and the author too. And depostit them through the database is not necessary.
$table->timestamps();
Next, the insert. Why not using the model eloquent/doctrine? Even if you want to insert a trilliard records, why not put ? instead created_at, updated_at is null, wrap it in DB::raw and to pass to now()?

title text? must be the string 99% probability
content type longText? or enough text, if any, should be json, too, most likely

So not almost everything. - Kevon.Barrows commented on March 20th 20 at 11:49
@Armand,
InnoDB the default, utf8 is used not only utf8mb4.

title text? must be the string 99% probability
content type longText? or enough text, if any, should be json, too, most likely

I agree with a dedicated(lost in copy and paste).
Next, the insert. Why not using the model eloquent/doctrine? ?

This idea I do not support.
at lark have created_at and updated_at, and the author too. And depostit them through the database is not necessary.

They are of type timestamp, which in contrast to the datetime less range and it depends on time zone. - enoch commented on March 20th 20 at 11:52
@Cleora51, less range, Yes, but created_at and updated_at so far, that fits. There needs to be changes on the mysql level, either at the framework/eloquent', but clubbing their bikes so don't need. Or datetime, and so that would be compatible with ->timestamps() persisted, or anywhere else. - Kevon.Barrows commented on March 20th 20 at 11:55

Find more questions by tags Laravel