php - 未定义的变量:routes/web.php LARAVEL 中的总数
问题描述
我在将变量hours
从控制器传递到刀片模板时遇到问题。怎么了?
网页.php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
Route::get('/hours', 'easyController@hours');
//widok dodawania godzin
Route::get('/hours/add', 'easyController@add');
//zapisywanie do bazy danych
Route::post('/hours', 'easyController@save');
//usuwanie z bazy danych
Route::delete('/hours/{id}', 'easyController@delete');
//suma czasu pracy z bazy
Route::get('/hours', function(){
return view('hours', ['total' => $total]);
});
控制方法:
public function pass(){
$total = DB::table('hours')->select(DB::raw("SEC_TO_TIME( SUM( TIME_TO_SEC('total'))) as suma"))->value('suma');
return view('hours', ['total' => $total]);
}
hours.blade.php:
<p>{{$total}}</p>
解决方案
您应该将 web.php 路由文件更改为
Route::get('/hours', function(){
$total = DB::table('hours')->select(DB::raw("SEC_TO_TIME( SUM( TIME_TO_SEC('total'))) as suma"))->value('suma');
return view('hours', ['total' => $total]);
});
或者更好
Route::get('/hours', 'easyController@pass');
推荐阅读
- jquery - 多个模型使用Tuple时获取DropDownList的变化函数
- php - 响应式汉堡包/下拉菜单在 wordpress 网站中不起作用
- webstorm - 文件观察器:“编译目录时必须指定输出目录”
- python - 计算 Pandas 系列中的值组
- python - 防止 Django 的 JsonResponse 序列化我的字符串
- laravel - 如何在 Laravel Homestead 中启用 php-Mcrypt 扩展
- python - 如何在文件名中插入零以使它们的长度相同
- java - 使用JpaPagingItemReader时spring批处理如何在内部初始化状态?
- scala - 从案例类集合创建 Flink DataStream 时“未找到隐含”
- python - 爬虫脚本运行没有错误,但没有我预期的输出 excel