我想做类似这样的事情,以下是代码示例:
public function handle()
{
$user = Auth::user()->name;
$ABC = ABC::find($id);
$author = $ABC->author;
if(!$user == $author){
echo "He can comment";
}
else{
//delete comment
}
return redirect()->back();
}
只有帖子的所有者可以添加评论我想用中间件来做,有人可以帮帮我吗?
答案 0 :(得分:3)
例如,
<?php
namespace Lame\Http\Middleware\Comment;
class CanAddComment
{
public function handle($request, Closure $next)
{
$user = Auth::user()->name;
$ABC = ABC::find($id);
$author = $ABC->author;
if($user == $author){
return redirect()->back();
}
return $next($request);
}
}