如何在h3标签之间将此路由输出用于我的索引页面

时间:2017-05-15 10:46:14

标签: php database html5 laravel-5 laravel-5.3

我的web.php

Route::get('/index',function()
{

    $count_total = DB::table('vendors')->count('id');

    return  $count_total;
}); 

在我的index.blade.php

<h3>  </h3>

<p>Vendors</p>

2 个答案:

答案 0 :(得分:0)

试试这个......

Route::get('/', function () {
    return view('index', ['count_total' => $count_total]);
});
index.blade.php中的

<h3> {{$count_total}} </h3>

<p>Vendors</p>

答案 1 :(得分:0)

这样做

Route::get('/index',function()
{

    $count_total = DB::table('vendors')->count('id');

    return view('index',compact('count_total'));
}); 

然后在你的index.blade.php

<h3> {{$count_total}} </h3>

<p>Vendors</p>