我在一個函數中有三個變量articles、users和matches。我希望能夠在調用該函數時列出這三個變量的所有內容。目前,當我 dd() 任何變量時,我都會獲取內容,但我希望在調用函數時從所有三個變量獲取內容。任何幫助表示贊賞。這是我的代碼。網頁.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條經驗 獲得超4個贊
返回包含所有值的數組。
public function getAll()
{
return [
'articles' => Article::get(),
'users' => User::get(),
'matches' => Match::get()
];
}
然后您可以按值類型選擇每一項,
$values = getAll();
$articles = $values['articles'];
///etc...
- 1 回答
- 0 關注
- 109 瀏覽
添加回答
舉報
0/150
提交
取消