我在一個函數(shù)中有三個變量articles、users和matches。我希望能夠在調(diào)用該函數(shù)時列出這三個變量的所有內(nèi)容。目前,當我 dd() 任何變量時,我都會獲取內(nèi)容,但我希望在調(diào)用函數(shù)時從所有三個變量獲取內(nèi)容。任何幫助表示贊賞。這是我的代碼。網(wǎng)頁.phpRoute::get('/dashboard', 'DashboardController@index')->name('dashboard.index');DashboardController.phppublic function getAll(){ $articles = Article::get(); $users = User::get(); $matches = Match::get();}
1 回答

GCT1015
TA貢獻1827條經(jīng)驗 獲得超4個贊
返回包含所有值的數(shù)組。
public function getAll()
{
return [
'articles' => Article::get(),
'users' => User::get(),
'matches' => Match::get()
];
}
然后您可以按值類型選擇每一項,
$values = getAll();
$articles = $values['articles'];
///etc...
- 1 回答
- 0 關(guān)注
- 104 瀏覽
添加回答
舉報
0/150
提交
取消