首页 > 解决方案 > 是否可以在 Laravel 8 中返回 2 个变量?

问题描述

//Create Borang Pendaftaran
public function CreateForm()
{
    $names = DB::table('pendaftaran')
    ->where('isActive',1)
    ->orderBy('id','desc')
    ->get();

    $names2 = DB::table('pendaftaran')
    ->where('isActive',0)
    ->orderBy('id','desc')
    ->get();

    return view('contact',['names' =>$names]); 
}

我所做的更改是

返回视图('联系人',['names' =>$names,$names2]);

标签: phplaravellaravel-8

解决方案


使用这个:

 $contact= [
    'name'  => $names,
    'names2'   => $names2,
   
 ];
 return view('contact',comapact('contact');

推荐阅读