2017-04-04 30 views
0

Laravel 5.3.31とPHP 7.1.2を使用してホームステッドを使用してウェブサイトを作成しました。 Laravel 5.3.31とPHP 7.1.3を使用して、リモートサーバーにホストされているサイトと同じサイトを持っています。モデルのコレクションの代わりに配列のコレクションを返すクエリ

I持って私のビューのいずれかで、次のコード:家産サイトで

$users = \DB::table('users')->get(); 
dd($users); 

、私は次のような結果を得る:私のリモートサーバー上

Collection {#327 ▼ 
    #items: array:1 [▼ 
    0 => {#334 ▼ 
     +"uid": 1 
     +"user_name": "test" 
     +"email": "[email protected]" 
     +"password": "somehashcode" 
     +"status": "active" 
     +"remember_token": "priEYh5ewdq2IlwCwOyNc8x1w0L1zNdWHV1wLznaBfhxoWex4rDvb8lijc5T" 
     +"created_at": "2017-03-20 18:30:46" 
     +"updated_at": "2017-03-28 17:12:49" 
    } 
    ] 
} 

、一方で、私の代わりにこの結果を得る:

Collection {#320 ▼ 
    #items: array:1 [▼ 
    0 => array:16 [▼ 
     "uid" => 1 
     0 => 1 
     "user_name" => "test" 
     1 => "test" 
     "email" => "[email protected]" 
     2 => "[email protected]" 
     "password" => "somehashcode" 
     3 => "somehashcode" 
     "status" => "active" 
     4 => "active" 
     "remember_token" => "WnKr77qKbgRwekZEdc9DhjLncYre5h7WvZrW7OkpOG8FZJuNFxC0CqRA5lEK" 
     5 => "WnKr77qKbgRwekZEdc9DhjLncYre5h7WvZrW7OkpOG8FZJuNFxC0CqRA5lEK" 
     "created_at" => null 
    6 => null 
    "updated_at" => "2017-04-03 19:49:50" 
    7 => "2017-04-03 19:49:50" 
] 

] }

このため、リモートサーバーで$ user-> uidを実行することができず、おそらくこれが原因である可能性があります。何か案は?これはPHPの問題でしょうか?

+0

ソリューションは別のボードにあります。問題はconfig/database.phpファイルにありました。 'fetch' => PDO :: FETCH_OBJという行がありませんでした。 https://laracasts.com/discuss/channels/laravel/query-returning-collection-of-arrays-instead-of-collection-of-models – user3018580

+0

解決策を見つけたので、自分で質問に答えるのはなぜですか? –

答えて

0

そのPDO構成の問題は、私は

/* 
|-------------------------------------------------------------------------- 
| PDO Fetch Style 
|-------------------------------------------------------------------------- 
| 
| By default, database results will be returned as instances of the PHP 
| stdClass object; however, you may desire to retrieve records in an 
| array format for simplicity. Here you can tweak the fetch style. 
| 
*/ 

'fetch' => PDO::FETCH_OBJ, 

マイdatabase.phpでファイルに次の行が欠落していた/ database.phpでこの

設定に関連すると思います。私がそれを加えたら、すべてが順調でした。

クレジット番号:https://laracasts.com/discuss/channels/laravel/query-returning-collection-of-arrays-instead-of-collection-of-models