Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Lavel/PHP中正确显示关联数组的结果_Php_Mysql_Arrays_Laravel - Fatal编程技术网

在Lavel/PHP中正确显示关联数组的结果

在Lavel/PHP中正确显示关联数组的结果,php,mysql,arrays,laravel,Php,Mysql,Arrays,Laravel,我试图在Laravel中显示查询中的姓名列表,但无法使结果正确显示 以下是我的控制器中的内容: public function getSettings() { $contents = explode(",", File::get(storage_path('app/public/users/0/config/social_module/buddy.txt'))); foreach($contents as $key => $value){ $buddylis

我试图在Laravel中显示查询中的姓名列表,但无法使结果正确显示

以下是我的控制器中的内容:

public function getSettings()
{
    $contents = explode(",", File::get(storage_path('app/public/users/0/config/social_module/buddy.txt')));
    foreach($contents as $key => $value){
        $buddylist[$value] = User::select('fullname as name')->where('id', $value)->get();
    }
    return view('welcome', compact('buddylist'));
}
以下是我的观点:

    @foreach($buddylist as $buddy)
    <ul>
        <li>{{ $buddy }}</li>
    </ul>
    @endforeach
打印(内容)

打印(buddylist)

使用而不是
get()
-

$buddylist[$value] = User::select('fullname as name')->where('id', $value)->first();
在你看来-

@foreach($buddylist as $buddy)
<ul>
    <li>{{ $buddy->name }}</li>
</ul>
@endforeach
@foreach($buddylist作为$buddy)
  • {{$buddy->name}
@endforeach
执行
print\r($contents)
print\r($buddylist)
并在此处发布结果。您想显示什么?只显示名称,而不是类似json的对象。
 Array ( [1] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Alix Earnshaw ) [original:protected] => Array ( [name] => Alix Earnshaw ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [2] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Horacio Esgate ) [original:protected] => Array ( [name] => Horacio Esgate ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [3] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Patrizia Anthony ) [original:protected] => Array ( [name] => Patrizia Anthony ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [4] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Ann-marie McLewd ) [original:protected] => Array ( [name] => Ann-marie McLewd ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [5] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Boote Poulsum ) [original:protected] => Array ( [name] => Boote Poulsum ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [12] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Any Bandy ) [original:protected] => Array ( [name] => Any Bandy ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [43] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Francene Lelliott ) [original:protected] => Array ( [name] => Francene Lelliott ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [74] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Ingelbert Abdy ) [original:protected] => Array ( [name] => Ingelbert Abdy ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [23] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Nickolaus Di Biaggi ) [original:protected] => Array ( [name] => Nickolaus Di Biaggi ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [67] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Constantina Wreight ) [original:protected] => Array ( [name] => Constantina Wreight ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) [32] => Illuminate\Database\Eloquent\Collection Object ( [items:protected] => Array ( [0] => App\User Object ( [table:protected] => users [fillable:protected] => Array ( ) [hidden:protected] => Array ( [0] => password ) [primaryKey:protected] => id [keyType:protected] => bigInteger [timestamps] => [remember_token] => [connection:protected] => mysql [incrementing] => 1 [with:protected] => Array ( ) [withCount:protected] => Array ( ) [perPage:protected] => 15 [exists] => 1 [wasRecentlyCreated] => [attributes:protected] => Array ( [name] => Clarissa Coomer ) [original:protected] => Array ( [name] => Clarissa Coomer ) [changes:protected] => Array ( ) [casts:protected] => Array ( ) [dates:protected] => Array ( ) [dateFormat:protected] => [appends:protected] => Array ( ) [dispatchesEvents:protected] => Array ( ) [observables:protected] => Array ( ) [relations:protected] => Array ( ) [touches:protected] => Array ( ) [visible:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) ) ) ) )
$buddylist[$value] = User::select('fullname as name')->where('id', $value)->first();
@foreach($buddylist as $buddy)
<ul>
    <li>{{ $buddy->name }}</li>
</ul>
@endforeach