Php 如何显示两个变量的结果laravel

Php 如何显示两个变量的结果laravel,php,laravel,Php,Laravel,我想在主页上显示控制器的两个功能的结果。 我想从计算机表中数一数有多少戴尔和多少IBM public function ibm() { $ibm= DB::table('computers') ->where( 'name', 'IBM')->count(); return view('welcome', ['ibm'=>$ibm]); } public function dell(

我想在主页上显示控制器的两个功能的结果。 我想从计算机表中数一数有多少戴尔和多少IBM

public function ibm()
    {
        $ibm= DB::table('computers')
            ->where( 'name', 'IBM')->count();
 
        return view('welcome', ['ibm'=>$ibm]);
 
    }
 
 
    public function dell()
    {
        $dell= DB::table('computers')
            ->where( 'name', 'DELL')->count();
 
        return view('welcome', ['dell'=>$dell]);

 }
Route web.php:

Route::get('welcome','ComputerController@ibm');
Route::get('welcome','ComputerController@dell');
欢迎使用.blade.php

<php>

   DELL<p>{{  $dell ?? '' }}</p>

    IBM<p>{{  $ibm ?? '' }}</p>
</php>

戴尔{{$DELL???''}

IBM{{$IBM???''}


不幸的是,我只得到其中一个变量的结果。另一个不显示结果

您不能一次用相同的方法路由定义相同的URI,因此请删除一个:

Route::get('welcome','ComputerController@ibm');
您的控制器将是:

public function ibm()
{
    $ibm= DB::table('computers')
        ->where('name', 'IBM')->get()->count();
    $dell= DB::table('computers')
        ->where('name', 'DELL')->get()->count();
 
    return view('welcome', ['ibm' => $ibm, 'dell' => $dell]);
 }

您不能一次用相同的方法路由定义相同的URI,因此请删除一个:

Route::get('welcome','ComputerController@ibm');
您的控制器将是:

public function ibm()
{
    $ibm= DB::table('computers')
        ->where('name', 'IBM')->get()->count();
    $dell= DB::table('computers')
        ->where('name', 'DELL')->get()->count();
 
    return view('welcome', ['ibm' => $ibm, 'dell' => $dell]);
 }

如果需要将它们放在同一个页面上,则将其作为一个单独的操作来获取这两个页面的数据。不能使用相同的路径和方法定义多个路由。如果需要在同一页上定义多个路由,请将其设置为一个单独的操作,以获取这两个路由的数据。您不能用相同的路径和方法定义多个路由。不幸的是,我的结果为空。两个变量。@mike我更新了,再次检查mm。。。没有更改在
name
字段中是否有名为
IBM
的数据?当然有。不幸的是,我的结果为空。两个变量。@mike我更新了,再次检查mm。。。没有更改在
name
字段中是否有名为
IBM
的数据?当然有。