Laravel_DB
環境: Laravel@9.52.4 migrate 済みの migration ファイルを削除してしまい、php artisan migrate:reset で Migration not found とエラーが出てしまった場合。 solution) php artisan migrate:fresh >>> DB全てのテーブルが削除された後、migrate する処理 …
環境: laravel@8.83.23 jensseger/laravel-mongodb@3.8.0 Model Structure Profile: { roles: [’admin’] } $profile = App\Profile::find(1); $profile->roles = array_push($profile->roles, 'superAdmin') >>> error: Indirect modification of overloade…
環境: laravel@8.79.0 Jenssegers/mongodb@3.8.4 サーチ対象の model 構造は以下とする Order { _id: ********, shippingStatus: [ "status" => "発送完了", "shippingMethod" => "クロネコヤマト", "inquiryNumber" => "11111111" ] } Order model から shi…
環境: 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@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…
PHPをUpgrade sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install libapache2-mod-php8.0 sudo a2dismod php7.2 sudo a2enmod php8.0 sudo apt-get install php8.0-dom php8.0-mbstring php8.0-zip php8.0-mysql php8.0-comm…
laravel@7.28.4 jensseger/laravel-mongodb@3.7.3 $result = myModel::raw(function($collection){ return $collection->aggregate([ ['$sample' => ['size' => 3]] ]); }) ref: github.com docs.mongodb.com stackoverflow.com
updated: 2022/3/29 環境: laravel@7.28.4 mongodb-php-driver@1.7 jensseger/laravel-mongodb@3.7.0 編集したいprofielDetail model のstructureは下記とする。 Userモデルは一つのProfileDetailモデル(hasOne)を持つ。 hasOneModel では protected $filla…
Laravel@5.8.33 mongoDB@4.0.10 あるEloquent ORMのネストされたデータdetails['description']をアップデートしたい。 $target = App\ModelName::first() $target->details['description'] >>> "test" と返るので直接 $target->details['description'] = "up…
mysql の select XX に当たるのが mongoDB では projection 'user_id' => 1 は true という意味 参考: github.com jenssegers/laravel-mongodb を使わないで mongoDB php driver を使うなら 参考: MongoDB\Collection::findOne() — PHP Library Manual 1.4…
updated: 2021/6/1 jenssegers/mongodb の mysql relationships で使用可能なことが確認済み php artisan make:factory FACTORY_NAME factory1 factory2 seeds/DatabaseSeeder.php おまけ ランダムな文字列を生成 return [ 'randomText' => $faker->regexify…
updated: 2018/10/1 Mysql relationships については下記参照 monteecristoo.hatenablog.com mongoDBとMysqlをjoin して返したい場合、mongoDBはjoinに対応していないので、 PixieImage は mongoDB上のデータベース user はmysql のデータベース さらにこれ…
データベーステーブルを適切に削除しなかったため。 solution: php artisan migrate:refresh //
// App\User ===> App\MongoMessage Mysql Relationships App\MessageGroup ===> App\MongoMessage hasMany Relationships App\User public function mongoMessages() { return $this->hasMany(MongoMessage::class); } App\MessageGroup public function mo…
// updated: 2018/4/14 first() get() >>> get() で複数の collection が返ってくるのでさらに処理したい場合は foreach で処理 e.g.) $messages = App\Message::whereNull("body")->get(); foreach($messages as $message) { $mssage->delete(); } whereIn(…
// setting up Mysql Relationships create the route and controller fetch the data from mongoDB extract the value from the response(3) fetch the data from Mysql using the value(4) return the response 1. @app\user use Jenssegers\Mongodb\Eloqu…
// App\User >>>> Mysql based Database use Jenssegers\Mongodb\Eloquent\HybridRelations; use App\MongoMessage; class User extends Authenticatable { use HybridRelations; use MongoMessage; public function mongoMessages() { return $this->hasMan…
// tinker $mongoUser = new MongoUser(['id' => 1, 'name' => 'Max']); $mongoMessage = new MongoMessage(['id' => 1, 'group' => '1', 'body' => 'Something', 'sender' => 'max', 'receiver' => 'Monica']); $mongoMessage = $mongoUser->mongoMessages(…
// App/MongoUser namespace App; use Moloquent; use MongoMessage; class MongoUser extends Moloquent{ protected $connection = 'mongodb'; protected $collection = 'mongoUsers'; public function mongoMessages() { return $this->embedsMany('MongoM…
// cloud9 上で php artisan migrate:reset 時に下記のエラー SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = c9 and table_name = migrations) composer dump-autoload してもダメな時 な…
// updated: 2018/3/6 jenssegers/laravel-mongodb を導入するメリット MySQL Relations If you're using a hybrid MongoDB and SQL setup, you're in luck! The model will automatically return a MongoDB- or SQL-relation based on the type of the rela…
updated: 2018 9/26 Error: In Database.php line 198: No suitable servers found ('serverSelectionTryOnce' set) : [connection refused calling ismaster on '127.0.0.1:27017'] mongoDB と mysql を使った multiple Database 環境で php artisan migrat…
// updated: 2018/1/17 public function up() { Schema::connection('mongodb')->create('group_messages', function (Blueprint $collection) { $collection->increments('id'); $collection->timestamps(); $collection->string('body');〇 $collection->u…
// updated 2018/1/5 Installation monteecristoo.hatenablog.com monteecristoo.hatenablog.com Laravel Configuration @config\app.php add the service provider Jenssegers\Mongodb\MongodbServiceProvider::class, @config/database.php 'mongodb' => […
Installation composer require predis/predis @web.php Route::get('/redis_test', function() { print_r(app()->make('redis')); } // Illuminate\Redis\RedisManager Object ( [driver:protected] => predis [config:protected] => Array ( [default] => …
create a Seed file php artisan make:seeder UsersSeeder register Seed file @DatabaseSeeder.php use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder{ public function run() { $this->call(UsersSeeder::class); }} define UsersSeed…
// php artisan make:migration create_messages_table --create="messages" Schema::create付きのmigration fileが生成される。 function up → php artisan migrate した時の動作 funciton down → php artisan migrate:rollback した時の動作 migrateをやり…
Relationships model A: User protected $fillable = [ DBのカラム] public function messages) { return $this->hasMany(Message::class); } model B: Message protected $fillable = [ DBのカラム] foreign_key は登録しなくてOK public function users() …