我想允许用户仅CRUD他们拥有的帖子。我不想创建一个新的中间件,而是利用现有的中间件。那么,可以扩展Entrust的默认中间件以适应这个目的吗?
class PostsController extends Controller
{
public function __construct()
{
$this->middleware('auth');
$this->middleware('role:blogger|owner'); // <-- implement additional logic in here
}
...
}
答案 0 :(得分: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();