2015-12-21 29 views
3

我喜歡用dd函數進行調試。這一次,當我用它來顯示約會列表時,我看不到(無法點擊的箭頭)屬性和原始數據。我得到括號[ …19]而不是顯示爲什麼。Laravels的DD輔助函數是否正常工作?

Collection {#3061 ▼ 
    #items: array:548 [▼ 
    0 => Appointment {#821 ▼ 
     #table: "appointments" 
     #fillable: array:16 [ …16] 
     #connection: null 
     #primaryKey: "id" 
     #perPage: 15 
     +incrementing: true 
     +timestamps: true 
     #attributes: array:19 [ …19] 
     #original: array:19 [ …19] 
     #relations: array:2 [ …2] 
     #hidden: [] 
     #visible: [] 
     #appends: [] 
     #guarded: array:1 [ …1] 
     #dates: [] 
     #dateFormat: null 
     #casts: [] 
     #touches: [] 
     #observables: [] 
     #with: [] 
     #morphClass: null 
     +exists: true 
     +wasRecentlyCreated: false 
    } 
    1 => Appointment {#822 ▶} 
    2 => Appointment {#823 ▶} 
    3 => Appointment {#824 ▶} 
    4 => Appointment {#825 ▶} 
    5 => Appointment {#826 ▶} 
    6 => Appointment {#827 ▶} 
    7 => Appointment {#828 ▶} 

,後來在列表中,我甚至不能預約看到裏面(沒有箭頭):

81 => Appointment {#902 ▶} 
    82 => Appointment {#903 ▶} 
    83 => Appointment {#904 ▶} 
    84 => Appointment {#905 ▶} 
    85 => Appointment {#906 …23} 
    86 => Appointment {#907 …23} 
    87 => Appointment {#908 …23} 
    88 => Appointment {#909 …23} 
    89 => Appointment {#910 …23} 
    90 => Appointment {#911 …23} 

但是當我用var_dump,我的數據看起來不錯:

array(548) { 
     [0]=> 
     array(21) { 
     ["id"]=> 
     int(149) 
     ["appointmenttype_id"]=> 
     NULL 
     ["appointmentlocationtype_id"]=> 
     NULL 
     ["appointment_start"]=> 
     object(Carbon\Carbon)#812 (3) { 
      ["date"]=> 
      string(26) "2015-12-21 07:00:00.000000" 
      ["timezone_type"]=> 
      int(3) 
      ["timezone"]=> 
      string(16) "America/New_York" 
     } 
     ["appointment_end"]=> 
     object(Carbon\Carbon)#811 (3) { 
      ["date"]=> 
      string(26) "2015-12-21 09:00:00.000000" 
      ["timezone_type"]=> 
      int(3) 
      ["timezone"]=> 
      string(16) "America/New_York" 
     } 

其他人遇到過這種情況?

回答

5

這是一個不太知名的回報太大的結果列表的警告。通常,dd()旨在簡要概述您要返回的數據,並在較小的數據組上處理「向下鑽取」。一旦你達到了某個數字(我忘記了確切的數字,500也許?),該功能不再起作用。

如果您確實需要在代碼中使用它的地方之前,看到這個數據,使用一個limit()條款你get()結果之前,或使用dd($example[0])看到一個結果的詳細信息。希望有所幫助!

+0

超級感謝@timlewis! – user3489502

1

不是dd()中的錯誤,只是如何配置底層Sympony VarDumper

我相信有問題的線路是this one其中有$maxDepth到20但我沒有檢查過。

看着Laravel Dumperlogic似乎沒有辦法從Laravel中覆蓋此項。

1

我已經找到一種方法來解決這個問題,但不建議,如果你真的想甩了整個對象,添加以下代碼段/bootstrap/autoload.php

if (! function_exists('dd')) { 
    /** 
    * Dump the passed variables and end the script. 
    * 
    * @param mixed 
    * @return void 
    */ 
    function dd() 
    { 
     array_map(function ($x) { 
      $dumper = 'cli' === PHP_SAPI ? new \Symfony\Component\VarDumper\Dumper\CliDumper() : new \Illuminate\Support\Debug\HtmlDumper(); 
      $cloner = new \Symfony\Component\VarDumper\Cloner\VarCloner(); 
      $cloner->setMaxItems(-1); 
      $cloner->setMaxString(-1); 
      $dumper->dump($cloner->cloneVar($x)); 
     }, func_get_args()); 

     die(1); 
    } 
} 

這必須是行上面添加:

要求DIR '/ .. /供應商/ autoload.php';。

它重寫了laravel dd函數,並在轉儲之前在Symfony VarCloner對象上設置了「setMaxItems」和「setMaxString」。