0

我想允许用户只对他们拥有的帖子进行 CRUD。我不想创建新的中间件,而是利用现有的中间件。那么,可以扩展 Entrust 的默认中间件以适应这个目的吗?

class PostsController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
        $this->middleware('role:blogger|owner'); // <-- implement additional logic in here
    }

    ...
}
4

1 回答 1

0
 @if (Auth::id() === $user->id){
     Edit
    }

如果您在您的Kernel.php

protected $routeMiddleware = [ 'auth' => '...' ]

在您的构造中:

public function __construct()
{
    $this->middleware('auth', ['only' => ['create']]);
}

将 eloquent 与 Entrust 一起使用:

$users = User::whereHas('roles' => function($q){
$q->where('name', 'my-user-role')
})->get();
于 2016-04-28T19:48:01.053 回答