LoginSignup
0
0

More than 3 years have passed since last update.

mysqlのデフォルト値の設定

Posted at

やりたいこと

デフォルトのプロフィール画像を設定したい。

マイグレーションでのデフォルト値設定

カラムにデフォルト値を設定するには->default('[値]')をつけるだけです。

    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->string('profile_image')->nullable()->comment("プロフィール画像")->default('default_icon.jpeg');
        });
    }

profile_imageカラムにdefault_icon.jpegをデフォルト値を設定しました。

あとはストレージにdefault_icon.jpegを置いとくだけ。

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