【发布时间】:2016-07-14 14:13:30
【问题描述】:
我想在 laravel 中为我的网络应用程序创建一个功能(我是新手),每个帖子/评论/主题(在我的情况下)用户都可以进行 upVote 和 downVote。现在我正在使用 upVote,但它不起作用。
在视图中(welcome.blade.php) 我有:
<a href="{{ route('Voteplus', ['name' => $Theme->name]) }}"> <img class="media-object" style="height:40px; width:40px;" src="images/upVote.svg" alt="..."></a>
其中 $Theme->name 是用户想要投票/喜欢的名称(随便)。
路线:
Route::put('/', [
'uses'=>'Vote@VotePlus',
'as' =>'Voteplus' //Name of route
]);
还有控制器:
<?php
namespace App\Http\Controllers;
use App\NewTheme;
use DB;
class Vote extends Controller {
public function VotePlus($name){
DB::table('New_Themes')
->where('name', $name)
->increment('upVotes', 1);
$Themes = NewTheme::paginate(5);
return redirect()->route('welcome', ['Themes'=>$Themes]);
}
};
我正在尝试一切,但它不起作用。有人可以帮帮我吗?
【问题讨论】:
-
->where('title', $title)应该是->where('title', $name)? -
我改了还是不行
-
可能put路由错了,我用错了?
标签: php mysql database laravel