我有這樣的代碼:Laravel指定者()返回仍然在DB對象::原料
$response['data'] = DB::table('customers')
->select(DB::raw('name,email,address1,address2,postalcode,state_region,country_code,phone,created_at'))
->where('user_id',"=",Auth::user()->id)
->where('name','like',"%$search_value%")
->orWhere('address1',"%$search_value%")
->orWhere('email','like',"%$search_value%")
->orWhere('address2','like',"%$search_value%")
->orWhere('city','like',"%$search_value%")
->orWhere('postalcode','like',"%$search_value%")
->orWhere('state_region','like',"%$search_value%")
->orWhere('country_code','like',"%$search_value%")
->orWhere('phone','like',"%$search_value%")
->orderBy('name', $order)
->limit($length)
->offset($start)
->get()->toArray();
這一項的結果是這樣的:
'data' =>
array (size=10)
0 =>
object(stdClass)[194]
public 'name' => string '|Barbara User' (length=13)
public 'email' => string '[email protected]' (length=16)
public 'address1' => string 'address aaddress' (length=17)
public 'address2' => null
public 'postalcode' => string '00000000' (length=10)
public 'state_region' => string 'GA' (length=2)
public 'country_code' => string 'US' (length=2)
public 'phone' => string '12312312312' (length=10)
public 'created_at' => string '2017-01-02 15:20:20' (length=19)
1 =>
object(stdClass)[201]
public 'name' => string '|Barbara User' (length=13)
public 'email' => string '[email protected]' (length=16)
public 'address1' => string 'address aaddress' (length=17)
public 'address2' => null
public 'postalcode' => string '00000000' (length=10)
public 'state_region' => string 'GA' (length=2)
public 'country_code' => string 'US' (length=2)
public 'phone' => string '12312312312' (length=10)
public 'created_at' => string '2017-01-02 15:20:20' (length=19)
....
正如你所看到的,有即使我已經做了toArray()
,仍然是結果中的一個對象。
這似乎是什麼問題?
您的幫助將不勝感激!謝謝!
這是最好的答案。我不知道收集嘗試在每個項目上調用toArray()。 – devk