php artisan make:migration create_table
カラム(‘detail_id’)は空も許可する設定。memoも同様。
Schema::create('cash_journals', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('sub_category_id');
$table->unsignedBigInteger('detail_id')->nullable();
$table->foreign('detail_id')->references('id')->on('details');
$table->date('recorded_date');
$table->integer('income_amount');
$table->integer('amount_spent');
$table->string('memo', 50)->nullable();
$table->timestamp('updated_at')->useCurrent()->nullable();
$table->timestamp('created_at')->useCurrent()->nullable();
});
php artisan migrate
モデルを作る。
php artisan make:model Cashjournal
コントローラーを作る。
php artisan make:controller CashjournalController --resource
ルート情報
use App\Http\Controllers\CashjournalController;
Route::resource('cashjournals', CashjournalController::class);
続く
コメント