如何在 Laravel 的一个函数中返回三个变量的所有内容?

我在一个函数中有三个变量articles、users和matches。我希望能够在调用该函数时列出这三个变量的所有内容。目前,当我 dd() 任何变量时,我都会获取内容,但我希望在调用函数时从所有三个变量获取内容。任何帮助表示赞赏。这是我的代码。


网页.php


Route::get('/dashboard', 'DashboardController@index')->name('dashboard.index');

DashboardController.php


public function getAll()

{

    $articles = Article::get();

    $users = User::get();

    $matches = Match::get();

}


MMTTMM
浏览 48回答 1
1回答

GCT1015

返回包含所有值的数组。public function getAll(){    return [        'articles' => Article::get(),        'users' => User::get(),        'matches' => Match::get()    ];}然后您可以按值类型选择每一项,$values = getAll();$articles = $values['articles'];///etc...
打开App,查看更多内容
随时随地看视频慕课网APP