2016-11-02 2 views
1

これはコントローラである:ここ変換アレイ

public function paidCount($booking_id) { 
    $book = \App\ EventBookings::where('booking_id', '=', $booking_id) - > get(); 
    if ($book - > count() > 0) { 
     $cha = \App\ EventBookingCharges::where('booking_id', '=', $book[0] - > booking_id) - > where('charge_key', 'LIKE', 'contribution') - > where('status', 'LIKE', '1') - > get(); 
     if ($cha - > count() > 0) { 
      $meta = \App\ EventBookingsMeta::where('booking_id', '=', $cha[0] - > booking_id) - > where('meta_key', 'LIKE', 'used_coupon') - > value('meta_value'); 
      if ($meta - > count() > 0) { 
       return\ App\ Coupon::where('coupon_id', '=', $meta[0] - > coupon_id) - > increment('no_paid'); 
      } 
     } 
    } 
} 

この部分は問題です:私のデータベース内

$meta = \App\EventBookingsMeta::where('booking_id', '=', $cha[0]->booking_id)->where('meta_key', 'LIKE', 'used_coupon')->value('meta_value'); 
if ($meta->count() > 0) { 
    return \App\Coupon::where('coupon_id', '=', $meta[0]->coupon_id)->increment('no_paid'); 

meta_valueので、これはそれが見え、まさに配列です行の内側のようなものused_coupon

used_coupon   [1] used_coupon 210又は
[1、2、3]

($meta->count() > 0)習慣を整数として、それがエラーの原因となるように読めばザ。

+0

'count($ meta-> toArray())> 0'を試してください。配列を文字列に変換したい場合は、 'implode(" "、$ meta);' –

+0

@BalrajAllam私はそれを取得しないと申し訳ありません。私はこれに新しいです:D –

+0

あなたのエラーは?あなたは何を達成したいですか? –

答えて

0

私はあなたが配列としてmeta_valueを保存していないと思う、それは文字列として格納されます。

meta_valueを保存する列にはserialize()unserialize()を入力する必要があります。あなたはserialize($meta_value_array) としてmeta_valueストア、それを保存していて、使用unserialize($meta_value)を取得しているときに

は、DB内のフィールドmeta_valueのデータ型がTEXTである必要がありarray.Andとしてあなたにmeta_valueを与えるだろう。

これを参照してください。https://stackoverflow.com/a/21663077/4584028

関連する問題