我正在编写像"学校俱乐部管理系统"这样的东西,并在资源的权利授权上遇到一些问题.
假设有club,并且club有经理,我想在club用中间件管理之前检查用户是否是经理.
使用laravel 5.2
我 router看起来像那样:
Route::resource('club', 'ClubController');
我创建的中间件看起来像这样:
public function handle($request, Closure $next)
{
if (!Auth::check()){
// ask user to login
}
$club = Club::findOrFail($request->input('club'));
$user = Auth::user();
if (!$club->managers->contains($user)){
//tell user your are not manager .
}
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
但我没能得到俱乐部的身份requests.
我该如何解决这个问题?
提前致谢 .
例如,我有一个字符串:
The struct-of-application and struct-of-world
Run Code Online (Sandbox Code Playgroud)
使用re.sub,它将用预定义的字符串替换匹配项。如何用匹配内容的转换替换匹配?要获取,例如:
The [application_of_struct](http://application_of_struct) and [world-of-struct](http://world-of-struct)
Run Code Online (Sandbox Code Playgroud)
如果我编写了一个简单的正则表达式((\w+-)+\w+)并尝试使用re.sub,则似乎无法使用匹配的内容作为替换的一部分,更不用说编辑匹配的内容了:
In [10]: p.sub('struct','The struct-of-application and struct-of-world')
Out[10]: 'The struct and struct'
Run Code Online (Sandbox Code Playgroud) 我是python的新手.我想打印os模块中的所有可用功能:
1 functionName
2 functionName
3 functionName
Run Code Online (Sandbox Code Playgroud)
等等.
目前我正在尝试使用以下代码获得此类输出:
import os
cur = dir(os)
for i in cur:
count = 1
count += 1
print(count,i)
Run Code Online (Sandbox Code Playgroud)
但它打印如下:
2 functionName
2 functionName
2 functionName
Run Code Online (Sandbox Code Playgroud)
直到结束.
请帮我生成自动增加的数字列表,谢谢.