0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【備忘録】データベースのテーブル作成(Laravel)

Posted at

テーブル作成

コンテナに入った後、下記記載

php artisan make:migration create_tr_records_table

ファイルが作成されるのでcreate箇所にカラム情報を記載する

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('tr_records', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->foreignId('user_id')->nullable()->constrained('users');
            $table->timestamp('tr_date')->nullable($value = true);
            $table->string('part');
            $table->string('menu');
            $table->string('set_type');
            $table->float('weight_first', 8, 2);
            $table->integer('reps_first');
            $table->float('weight_second', 8, 2);
            $table->integer('reps_second');
            $table->float('weight_third', 8, 2);
            $table->integer('reps_third');
            $table->float('weight_fourth', 8, 2);
            $table->integer('reps_fourth');
            $table->float('weight_fifth', 8, 2);
            $table->integer('reps_fifth');
            $table->text('memo');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('tr_records');
    }
};

記載したらmigrateする

php artisan migrate

モデル作成

php artisan make:model TrRecord

コントローラ作成

php artisan make:controller TrRecordController
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?