在PostController创建帖子:
public function store(PostRequest $request, Topic $topic)
{
// Get user id.
$user = Auth::user();
if ($user->can('create')) {
//
}
}
相关策略:
class PostPolicy extends Policy
{
public function before(User $user)
{
if ($user->status > 0) {
return true;
}
}
public function create(User $user)
{
return true;
}
}
报错:
Call to undefined method IlluminateDatabaseQueryBuilder::can()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…