Php 如何在h3标记之间使用此路由输出到索引页
my web.phpPhp 如何在h3标记之间使用此路由输出到索引页,php,database,html,laravel-5,laravel-5.3,Php,Database,Html,Laravel 5,Laravel 5.3,my web.php Route::get('/index',function() { $count_total = DB::table('vendors')->count('id'); return $count_total; }); 在我的index.blade.php中 <h3> </h3> <p>Vendors</p> <h3> {{$count_total}} </h3> &
Route::get('/index',function()
{
$count_total = DB::table('vendors')->count('id');
return $count_total;
});
在我的index.blade.php中
<h3> </h3>
<p>Vendors</p>
<h3> {{$count_total}} </h3>
<p>Vendors</p>
<h3> {{$count_total}} </h3>
<p>Vendors</p>
卖主
试试这个
Route::get('/', function () {
return view('index', ['count_total' => $count_total]);
});
在index.blade.php中
<h3> </h3>
<p>Vendors</p>
<h3> {{$count_total}} </h3>
<p>Vendors</p>
<h3> {{$count_total}} </h3>
<p>Vendors</p>
{{$count\u total}
卖主
执行此操作
Route::get('/index',function()
{
$count_total = DB::table('vendors')->count('id');
return view('index',compact('count_total'));
});
然后在index.blade.php中
<h3> </h3>
<p>Vendors</p>
<h3> {{$count_total}} </h3>
<p>Vendors</p>
<h3> {{$count_total}} </h3>
<p>Vendors</p>
{{$count\u total}
卖主
请快速查看hi Bilal感谢您的回复…但我希望此输出显示在我索引中的h3标记之间…我如何链接此输出示例{{我需要此输出…请帮助}}@Veekee45我已更新我的答案。。你也可以这样回应。。。我将代码添加到控制器并按路由调用控制器,它工作得非常好…非常感谢您的大力帮助…做得好,兄弟,继续保持下去..感谢您的帮助sapnesh..但我收到了此错误“未定义变量:计数总数”在索引页上..我以前也尝试过,但我得到了同样的结果..有没有办法解决这个问题::get('/indexs',function(),当我将页重命名为索引时,该页正在获取..但当我重命名为索引..它显示“未定义变量:count_total”@Veekee45发布您的所有路线我将代码添加到控制器并按路线呼叫控制器,效果非常好…非常感谢您的大力帮助…做得好,兄弟,继续保持下去。@Veekee45谢谢!如果答案对您有帮助,您可以接受