2022-03-01から1ヶ月間の記事一覧

Laravel: 親モデルを削除と同時に子モデルを削除する cascading soft-delete / MySQL case and MongoDB case

環境: Laravel@8.79.0 Jenssegers/mongodb@3.8.4 前提: 親モデル >>> User.php MySQL子モデル >>> Post.php MongoDB子モデル >>> ProfileDetail.php case MySQL soft-delete に対応させる migration file に以下を加筆 Schema::create('users', function B…

Laravel MongoDB: mongodbを使用時にmigration file で table を定義する

環境 Laravel@8.79.0 Jenssegers/mongodb@3.8.4 migration をしなくても ORM から query することで DB に table を作成することができるが、 migration file を作って DB table を定義したい場合、 php artisan make:migration create_MONGO_TABLE_MODEL_ta…

Laravel MongoDB: Delete a table and items manually

環境 Laravel@8.79.0 Jenssegers/mongodb@3.8.4 php artisan tinker >>> @tinker session // Delete a table Schema::connection('mongodb')->drop('TABLE_NAME') // Delete items DB::connection('mongodb')->table('TABLE_NAME')->truncate() ref: stackov…