Questions tagged «laravel-middleware»

11
Laravel中间件将变量返回给控制器
我正在对用户进行权限检查,以确定他们是否可以查看页面。这涉及首先通过一些中间件传递请求。 我遇到的问题是在将数据返回到视图本身之前,我正在中间件和控制器中复制相同的数据库查询。 这是设置示例; --routes.php Route::get('pages/{id}', [ 'as' => 'pages', 'middleware' => 'pageUser' 'uses' => 'PagesController@view' ]); -PageUserMiddleware.php(PageUserMiddleware类) public function handle($request, Closure $next) { //get the page $pageId = $request->route('id'); //find the page with users $page = Page::with('users')->where('id', $pageId)->first(); //check if the logged in user exists for the page if(!$page->users()->wherePivot('user_id', Auth::user()->id)->exists()) …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.