ajax - 在laravel中单击按钮时如何增加DB中的计数值?
问题描述
当我单击该页面中的投票按钮时,我有Home.blade.php ,候选表中的计数值应该增加。
这是我的Home.blade.php
@foreach ($file as $show)
<div class="col-md-3">
<div class="card">
<img src="p3.png" alt="John" style="width:100%">
<div class="card-body">
<h5 class="title">President</h5>
<p class="card-text">Name : {{$show->name}}</p>
<!-- <p><button>VOTE</button></p> -->
<button type="button" class="vote">VOTE</button>
</div>
</div>
</div>
@endforeach
我有一个名为候选人的表名,当点击投票按钮时,数据库中的计数应该增加。我有一个叫做HomeController
请帮助我的控制器。谢谢
class Homecontroller extends Controller
{
public function pre()
{
$file = DB::table('candidate')
->select('name','branch')
->where('candidate.post_id', '=', 1)
->get();
return view('/home')->with('file',$file);
}
}
@foreach ($file as $show)
<div class="col-md-3" style="margin-bottom: 20px;">
<div class="card">
<img src="p3.png" alt="John" style="width:100%">
<div class="card-body">
<h5 class="title">President</h5>
<p class="card-text">Name : {{$show->name}}</p>
<a href="{{url("Homecontroller@count")}}"><p><button>VOTE</button></p> </a>
</div>
</div>
</div>
@endforeach
我已经使用函数重定向到控制器
在控制器中我使用了这个功能
public function Count(){
DB::table('candidate')->increment('count',1);
return view('/home');
}
仍然无法正常工作
这是我的路线
Route::get('/home','Homecontroller@count');
解决方案
推荐阅读
- python - 在 python 中使用 TASK_TRIGGER_LOGON 创建计划任务
- graph - 完整图中“广义”匹配的算法
- android - 可以在 Google Play 上为 Android TV 和智能手机发布相同的应用程序
- php - 如何用php中的变量替换url值?并在获取数组中获得动态结果?
- git - Git local 忽略符号链接的目录
- python - 理解 Flask 请求对象
- amazon-web-services - 为什么 AWS Glue 不支持将 SQL 作为 ETL 语言?
- python-3.6 - 尝试使用 python docx 模块从 word 文档中打印 20 行,但它只打印第一行
- java - BigDecimal setScale 方法语法不起作用
- c# - 变量像类型一样使用