monteecristoo’s blog

https://twitter.com/irakaarozo

Laravel_DB

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7 ⑩ 特定のcollectionのネストされたキーの値を取得する

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…

Laravel 5.x Factory と Faker で relational なモックアップを作る。

jenssegers/mongodb の mysql relationships で使用可能なことが確認済み php artisan make:factory FACTORY_NAME factory1 factory2 seeds/DatabaseSeeder.php php artisan db:seed これでfaker モックアップ + user と pixieImage のrelationship に整合性…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7 ⑨ Mysql relationships で mongoDB と mysql 上のデータを合わせて返す。

updated: 2018/10/1 Mysql relationships については下記参照 monteecristoo.hatenablog.com mongoDBとMysqlをjoin して返したい場合、mongoDBはjoinに対応していないので、 PixieImage は mongoDB上のデータベース user はmysql のデータベース さらにこれ…

php artisan db:seed でエラー

データベーステーブルを適切に削除しなかったため。 solution: php artisan migrate:refresh //

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7⑧ sample case

// 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…

Laravel 5.x よく使う query builder

// updated: 2018/4/14 first() get() >>> get() で複数の collection が返ってくるのでさらに処理したい場合は foreach で処理 e.g.) $messages = App\Message::whereNull("body")->get(); foreach($messages as $message) { $mssage->delete(); } whereIn(…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7⑦ convert mongoDB to Mysql

// 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…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7⑥ Mysql relationships test

// 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…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7⑤ EmbedsMany relationships test

// tinker $mongoUser = new MongoUser(['id' => 1, 'name' => 'Max']); $mongoMessage = new MongoMessage(['id' => 1, 'group' => '1', 'body' => 'Something', 'sender' => 'max', 'receiver' => 'Monica']); $mongoMessage = $mongoUser->mongoMessages(…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7④

// 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…

error: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = c9 and table_name = migrations)

// 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 してもダメな時 な…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7③ 導入するメリット

// 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…

Error: In Database.php line 198: No suitable servers found ('serverSelectionTryOnce' set) : [connection refused calling ismaster on '127.0.0.1:27017']

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…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7② migration file による validation

// 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…

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7 ①

// 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' => […

Laravel & redis 接続テスト

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] => …

Laravel Database Seed

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…

Laravel Migration file 操作

// 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をやり…

Laravel 5.4 Database Structure

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() …

jenssegers/laravel-mongodb installation PHP7.1 on cloud9 未解決

// updated: 2018/9/25 *エラーでworkspaceにアクセスできなくなることがあるのでworkspaceをクローンして実行 mongodbのsetup $ sudo pecl install mongodb → error Warning: Invalid argument supplied for foreach() in Command.php on line 249 Warning…