-
-
Save mikkame/0bb087029345dc08c07c29c6827b6f7f to your computer and use it in GitHub Desktop.
Laravelで足りないカラムを保存時に自動的に作ってくれるやつ
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 | |
protected static function boot() | |
{ | |
parent::boot(); | |
self::saving(function($me){ | |
$columns = array_flip(\Schema::getColumnListing($me->getTable())); | |
foreach($me->attributes as $key => $val) { | |
if (!isset($columns[$key])) { | |
Schema::table($me->getTable(), function (Blueprint $table) use($key) { | |
$table->string($key)->nullable(); | |
}); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment