在GridView的滚动上滚动整个屏幕(Scrolling the whole screen on GridView's scroll)
我有一个片段,在这个片段下面是一个容器(有时)包含一个GridWiew。 如何在GridView的滚动条上滚动整个屏幕?
I have a fragment and below this fragment a container which (sometimes) contains a GridWiew. How can I scroll the whole screen on GridView’s scroll?
原文:https://stackoverflow.com/questions/29513459
最满意答案
您可以为每个用户分别设置。 这将工作。 但是也很难维护,你可能需要写3次函数(登录,注销,CRUD等)。
但是,您可以使用授权创建单个项目。 开箱即用,Laravel为您提供了一种简单的方法,通过
Gate
授权和限制某些操作或通过Policy
限制模型。 您也可以通过Middleware
来限制URL。 看到你有3种不同的限制行为的方式。我的个人偏好是
Policy
因为它与模型绑定。 您拥有权限列表并为每个角色分配权限,例如:'create_sys_admin'。 然后将此权限链接到“root_admin”角色。 所以在你的政策中你可以写:public function createSysAdmin(User $user) { return $user->role->permissions->contains('create_sys_admin'); }
通过定义策略,我们可以检查控制器中的propser权限。 在控制器的任何功能中,您都可以检查适当的权限
if ( Auth::user()->cant('create_sys_admin', User::class) ) { return redirect()->back()->withErrors(['authorization' => 'You are not authorized to perform that action']); }
那只是一种方式。 正如我之前所说的,你也有盖茨和中间件。 在这里阅读更多: https : //laravel.com/docs/5.4/authorization
如果你想要一些东西,你可以使用这个包: https : //github.com/Zizaco/entrust 。
You could make separate setups for each users. That would work. But would also be difficult to maintain and you might have to write some functions 3 times (login, logout, CRUD, etc.).
However, you could create a single project using Authorizations. Out of the box, Laravel gives you an easy way to authorize and restrict some actions via
Gate
or restrict models viaPolicy
. You could also restrict URLs viaMiddleware
. See you have 3 different ways of restricting actions.My personal preference is
Policy
because it's bound to the model. You have a list of permissions and give each role their permissions, eg.: 'create_sys_admin'. Then link this permission to the 'root_admin' role. so in your policy you can write:public function createSysAdmin(User $user) { return $user->role->permissions->contains('create_sys_admin'); }
With the policy defined, we can check for propser permission in the controller. In any function in your controller you can always check for proper permissions
if ( Auth::user()->cant('create_sys_admin', User::class) ) { return redirect()->back()->withErrors(['authorization' => 'You are not authorized to perform that action']); }
That was just one way. As I previously said, you have Gates and Middlewares as well. Read more here: https://laravel.com/docs/5.4/authorization
If you want something already made, you can use this package: https://github.com/Zizaco/entrust.
相关问答
更多-
这要么得到第一条记录 Auth::user()->roles->first()->name 或使用循环 @foreach(Auth::user()->roles as $role) {{ $role->name }} @endforeach either this to get the first record Auth::user()->roles->first()->name or use a loop @foreach(Auth::user()->roles as $role) ...
-
您可以在现有模型对象上使用load函数来加载关系的数据。 $user->load('roles') return $user; You can use the load function on an existing model object to load a relationship's data. $user->load('roles') return $user;
-
对于初学者,我会建议你重新设计你的数据模型。 您的用户模型是您的身份验证器,这就是它应该关注的一切。 它不应该是商店或供应商,或其他任何东西。 供应商和商店应该是独立的模型,它们拥有“用户”。 此刻你正在做的事情违反了SOLID,就像你在这里提到的大部分答案一样。 特别是O或Open for extension,关闭以进行修改。 例如,如果用户是商店和供应商? 如果稍后再添加分配器类型,该怎么办? 你必须回到那个模型并添加更多的if / else语句,更多类型的关系等等...... 相反,我会考虑拥有“店铺 ...
-
您已使用auth过滤器,因此您应该在app/filters.php文件中检入auth过滤器: Route::filter('auth', function($route, $request) { // Login check (Default) if (Auth::guest()) return Redirect::guest('login'); // Admin check if(!in_array('admin', Auth::user()->roles->toArra ...
-
您可以为每个用户分别设置。 这将工作。 但是也很难维护,你可能需要写3次函数(登录,注销,CRUD等)。 但是,您可以使用授权创建单个项目。 开箱即用,Laravel为您提供了一种简单的方法,通过Gate授权和限制某些操作或通过Policy限制模型。 您也可以通过Middleware来限制URL。 看到你有3种不同的限制行为的方式。 我的个人偏好是Policy因为它与模型绑定。 您拥有权限列表并为每个角色分配权限,例如:'create_sys_admin'。 然后将此权限链接到“root_admin”角色。 ...
-
在您的User类中添加 public function roles() { return $this->belongsToMany('Role','assigned_roles'); } 然后,您可以获取特定用户的所有角色 $user = User::with('roles')->find(1); $roles = $user->roles; In your User class add public function roles() { return $this->belongsToM ...
-
为什么不创建一个“CompositeRoleProvider”,并使用Path-To-Level类型约定来访问每个从属角色提供者。 您仍然必须创建多个角色提供者,但您的复合或顶级提供者会为您完成所有工作。 我打算用ProfileProvider做类似的事情 why not create a "CompositeRoleProvider" with a Path-To-Level typew convention for accessing each subordinate role provider. Yo ...
-
要创建模型,只需使用以下内容: $user = User::create($attributes) 请注意,我之后没有调用get() 。 get()将执行返回Collection的查询。 我不确定你的Role模型是什么样的,但它现在应该可以正常工作。 To create a model simply use the following: $user = User::create($attributes) Notice that I did not call get() afterwords. get() ...
-
是的,使用ASP.NET的内置角色功能将非常有用。 将特定用户添加到角色后, Roles.AddUserToRole("Joe", "Web Developer"); 应用逻辑很容易,例如: if (User.IsInRole("Web Developer")) { //Do something } 此外, RolePrincipal类非常适合访问各种其他与角色相关的方法,例如获取特定角色的所有成员。 Yes it will be useful to use inbuilt role functio ...
-
我认为实现这一目标的最简单方法是通过自定义中间件定义。 检查默认的auth中间件并设计与此类似的新中间件。 只需用户登录,获取用户并检查他/她的角色。 如果他/她有管理员权限,则重定向到管理员页面等。 定义此中间件后,您可以修改路由并将此中间件附加到它们。 这将在此详细解释 I think the easiest way to achieve this is via custom middleware definition. Check the default auth middleware and des ...