Payment Request API が使用可能なブラウザか調べる方法

if(window.PaymentReqeust) {

  console.log("support")

} else {

  console.log("not support")

}

 

ただし、payment Request API が使用可能でかつ、クレジット情報が既にブラウザに保存済みか調べるためにはpaymentRequestオブジェクトを生成したのち、canMakePayment()を使用しないと確認できない。

 

f:id:monteecristoo:20201223212158p:plain

ref:

https://developer.mozilla.org/ja/docs/Web/API/Payment_Request_API/Using_the_Payment_Request_API

 

AWS Cloud9 で VFS Connection エラーでアプリケーションがうまく表示されない solved

updated: 2020/8/17

 

ブラウザのプラグインAdBlockやscript block が必要なscriptをブロックしている場合があるのでそれらを停止させる。

 

---------------------------------------------------------------------------------------------

環境:

AWS Cloud9

Laravel@6.18.35

laravel のバージョンをアップグレードしたら上記で対処できない場合が生じた。

以下で解決

app\Http\Middleware\TrustProxies.php

protected $proxies = '**';

に変更。

sudo service apache2 restart

>>> solved

 

ref:

https://teratail.com/questions/250858

https://readouble.com/laravel/6.x/ja/requests.html#configuring-trusted-proxies

list rendering + v-model : v-model にdynamic な値を割り当てる/ Vuetify: v-dialog + list rendering

updated: 2020/2/15

 

vue@2.6.11

vuetify@2.2.12

 

vuetify の v-dialog を v-for 内で使用するとき個別の値を v-model に割り当てないとdialog に正しい list の値がパスされない。

 

https://github.com/vuetifyjs/vuetify/issues/5246

 

そこで v-for="(item, index) in list" で index を生成し、v-mode="deleteDialog[index]" としたが正しく動作しなかった。

f:id:monteecristoo:20200214050850p:plain

f:id:monteecristoo:20200214050719p:plain

solution 1)

deleteDialog の値が update された後、$forceUpdate() する。

  <v-icon @click="initDeleteDialog">Delete</v-icon>

 

  methods: {

    initDeleteDialog(index) {

      this.deleteDialog[index] = true

      this.$forceUpdate()

    }

  }

 

ref)

https://vuejs.org/v2/guide/components-edge-cases.html#Forcing-an-Update

 

solution 2)

v-model はプロパティで指定すると正常に動作した。

f:id:monteecristoo:20200214051152p:plain

ref: 

https://forum.vuejs.org/t/how-do-i-have-dynamic-v-model/18833

 

 

See the Pen Vue Form by Cheah Jer Fei (@jeffhappily) on CodePen.

Vuex: stateの値にpayloadを使う場合の注意事項

vuex@3.1.2

 

Goal: shopping cart の中身を商品のIDごとに管理し、かつ各IDごとの数量を vuex stateに保持したい。また数量が1つずつではなく複数 cart に追加できるものとする。

 

const state = {

  products: []

}

 

const actions = {

  cart_addProduct({state, commit}, items) {

    if(state.products.length) {

      commit('CART_ADD_PRODUCTS', items)

    } else {

      commit('CART_INITIALIZE', items)

    }

  }

}

 

const mutations = {

  'CART_ADD_PRODUCTS' (state, items) {

    for(let i=0; i < items.length; i++) {

      const detectItem = state.products.find((product) => product.id === items[i].id)

      if(detectItem) {

        detectItem.quantity += items[i].quantity

      } else {

        state.products.push({

          name: items[i].name,

          price: items[i].price,

          quantity: items[i].quantity

        })

      }

    }

  },

  'CART_INITIALIZE' (state, items) {

    for(let i=0; i < items.length; i++) {

      state.products.push({

        name: items[i].name,

        price: items[i].price,

        quantity: items[i].quantity

      })

    }

  }

}

 

ここで

state.products.push(items[i]) のようにmutationのpayloadを直接stateに代入すると値がpayload参照型になってしまいquantityの+= item[i].quantityの部分で意図した値が取得できなくなる。

detectItem.quantity += items[i].quantityで加算ではなく、items[i].quantityが2倍された値が返値になる

そのため同一の値ではあるがオブジェクトをわざわざ成型している。

例えば

'CART_INITIALIZE' で state.products.push(items[i]) とし、

'CART_ADD_PRODUCTS' (state, items) {

  // do nothing

}

とした場合、

cart_addProduct(item) =>  CART_INITIALIZE => cart_addProduct(item) => CART_ADD_PRODUCTS

ここでCART_ADD_PRODUCTSはdo nothing にもかかわらずitemのプロパティが2度目のcart_addProduct(item) のitemのプロパティに勝手に更新される。

 

結論)

payloadがオブジェクトの場合、直接stateに代入しないでpayloadを使って新しくオブジェクトを作りstateに代入する。

jenssegers/laravel-mongodb Basic Usage on cloud9 with php7 ⑪ difference between embedsMany relationship and hasMany relationship

embedsMany: 子供側の model は mongoDB 内に collection が作成されず親の collection 内にデータがネストされる。 _id は自動で付与される。

f:id:monteecristoo:20200127211644p:plain

親: order 子: orderImage

$order = App\Order::where("user_id", 42)->first()

$order->orderImages()->create(["userEdit" => "test"]);

 

一方、hasMany は子供側も collection が作成され、子供側に親の id を付与したデータが作成される。

f:id:monteecristoo:20200127212140p:plain

 

子供

f:id:monteecristoo:20200127212334p:plain

user_id(自動で付与される)による collection 間の参照型

Laravel: model を任意のディレクトリに移動させたい場合

laravel@6.3

 

model を任意のディレクトリに移動させたい場合

  1. php artisan make:model MODEL_NAME
  2. 任意のディレクトリに移動
  3. php artisan make:migration CreateModel_nameTable
  4. php artisan migrate

**必ず migrate する前にディレクトリを移動させる。

 

 

** php artisan migrate 後にmodel を移動させた場合

php artisan migrate:rollback をして再度migrateしても元のディレクトリを参照してしまい

failed to open stream: No such file or directory'

とエラーが出るのでmigration ファイルを削除し再度migration を作成、migrate する。