如何在Eloquent ORM Laravel上使用var_dump公开数据


How could I expose data using var_dump on Eloquent ORM Laravel?

我是php开发的新手,我想使用var_dump在客户端调试我的php程序。

 $test= Admin::where("EPANTHERID","=",$email);
        var_dump($test);die();

在客户端,我收到这个

bject(Illuminate'Database'Eloquent'Builder)[187]  protected 'query' =>     object(Illuminate'Database'Query'Builder)[186]      protected 'connection' =>         object(Illuminate'Database'MySqlConnection)[179]          protected 'pdo' =>             object(PDO)[180]              ...          protected 'readPdo' => null          protected 'reconnector' =>             object(Closure)[185]              ...          protected 'queryGrammar' =>             object(Illuminate'Database'Query'Grammars'MySqlGrammar)[181]              ...          protected 'schemaGrammar' => null          protected 'postProcessor' =>             object(Illuminate'Database'Query'Processors'MySqlProcessor)[182]              ...          protected 'events' =>             object(Illuminate'Events'Dispatcher)[14]              ...          protected 'paginator' =>             object(Closure)[184]              ...          protected 'cache' =>             object(Closure)[183]              ...          protected 'fetchMode' => int 8          protected 'transactions' => int 0          protected 'queryLog' =>             array (size=0)              ...          protected 'loggingQueries' => boolean true          protected 'pretending' => boolean false          protected 'database' => string 'xinwen_development' (length=18)          protected 'tablePrefix' => string '' (length=0)          protected 'config' =>             array (size=9)              ...      protected 'grammar' =>         object(Illuminate'Database'Query'Grammars'MySqlGrammar)[181]          protected 'selectComponents' =>             array (size=11)              ...          protected 'tablePrefix' => string '' (length=0)      protected 'processor' =>         object(Illuminate'Database'Query'Processors'MySqlProcessor)[182]      protected 'bindings' =>         array (size=5)          'select' =>             array (size=0)              ...          'join' =>             array (size=0)              ...          'where' =>             array (size=1)              ...          'having' =>             array (size=0)              ...          'order' =>             array (size=0)              ...      public 'aggregate' => null      public 'columns' => null      public 'distinct' => boolean false      public 'from' => string 'ADMIN' (length=5)      public 'joins' => null      public 'wheres' =>         array (size=1)          0 =>             array (size=5)              ...      public 'groups' => null      public 'havings' => null      public 'orders' => null      public 'limit' => null      public 'offset' => null      public 'unions' => null      public 'lock' => null      protected 'backups' =>         array (size=0)          empty      protected 'cacheKey' => null      protected 'cacheMinutes' => null      protected 'cacheTags' => null      protected 'cacheDriver' => null      protected 'operators' =>         array (size=19)          0 => string '=' (length=1)          1 => string '<' (length=1)          2 => string '>' (length=1)          3 => string '<=' (length=2)          4 => string '>=' (length=2)          5 => string '<>' (length=2)          6 => string '!=' (length=2)          7 => string 'like' (length=4)          8 => string 'not like' (length=8)          9 => string 'between' (length=7)          10 => string 'ilike' (length=5)          11 => string '&' (length=1)          12 => string '|' (length=1)          13 => string '^' (length=1)          14 => string '<<' (length=2)          15 => string '>>' (length=2)          16 => string 'rlike' (length=5)          17 => string 'regexp' (length=6)          18 => string 'not regexp' (length=10)  protected 'model' =>     object(Admin)[178]      protected 'table' => string 'ADMIN' (length=5)      protected 'fillable' =>         array (size=1)          0 => string 'EPANTHERID' (length=10)      protected 'connection' => null      protected 'primaryKey' => string 'id' (length=2)      protected 'perPage' => int 15      public 'incrementing' => boolean true      public 'timestamps' => boolean true      protected 'attributes' =>         array (size=0)          empty      protected 'original' =>         array (size=0)          empty      protected 'relations' =>         array (size=0)          empty      protected 'hidden' =>         array (size=0)          empty      protected 'visible' =>         array (size=0)          empty      protected 'appends' =>         array (size=0)          empty      protected 'guarded' =>         array (size=1)          0 => string '*' (length=1)      protected 'dates' =>         array (size=0)          empty      protected 'touches' =>         array (size=0)          empty      protected 'observables' =>         array (size=0)          empty      protected 'with' =>         array (size=0)          empty      protected 'morphClass' => null      public 'exists' => boolean false  protected 'eagerLoad' =>     array (size=0)      empty  protected 'macros' =>     array (size=0)      empty  protected 'onDelete' => null  protected 'passthru' =>     array (size=12)      0 => string 'toSql' (length=5)      1 => string 'lists' (length=5)      2 => string 'insert' (length=6)      3 => string 'insertGetId' (length=11)      4 => string 'pluck' (length=5)      5 => string 'count' (length=5)      6 => string 'min' (length=3)      7 => string 'max' (length=3)      8 => string 'avg' (length=3)      9 => string 'sum' (length=3)      10 => string 'exists' (length=6)      11 => string 'getBindings' (length=11)

Eloquent似乎有某种机制阻止我使用var_dump访问数据。我该如何解决这个问题,或者有人能向我展示一种更好的调试php脚本的方法吗?非常感谢。

您应该使用:

$test= Admin::where("EPANTHERID","=",$email)->get();

$test= Admin::where("EPANTHERID","=",$email)->first();

如果CCD_ 1是唯一的,则对结果使用CCD_。

这是因为如果没有get()first()(以及其他一些方法),您的仅变量对象中就有一个包含查询的对象,而不是运行查询的结果(代码中的查询尚未启动)。