我无法让我的某个auth策略正常运行,导致授权尝试始终返回false.我甚至只是为了测试而强制函数返回true.我正在使用Laravel 5.4,这是我的政策功能:
public function can_modify_or_delete(User $user, Comment $comment)
{
return true;
}
Run Code Online (Sandbox Code Playgroud)
在我的AuthServiceProvider.php文件中,我已添加CommentPolicy到我现有的政策注册中.
protected $policies = [
'App\Models\Post' => 'App\Policies\PostPolicy',
'App\Models\Comment' => 'App\Policies\CommentPolicy',
];
Run Code Online (Sandbox Code Playgroud)
奇怪的是,该政策一直运作得很好.注释似乎没有被注册或没有被正确调用.
在我的路线:
Route::delete('/comments/{comment}', 'CommentsController@destroy');
Run Code Online (Sandbox Code Playgroud)
并在 CommentsController
public function destroy(Request $request, Comment $comment)
{
$this->authorize('can_modify_or_delete', $comment);
$comment->delete();
return response(['status' => 'Comment deleted'], 200);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,无论如何,授权检查都返回false.我错过了什么吗?仔细检查错别字,找不到任何错误.我还确认路由模型绑定正在按预期工作,因此它不是空资源问题.我尝试dd()了这个政策,甚至没有被召唤.
我正在为使用自定义UITableViewCell子类的UITableView开发自定义滑动事件.我把它包含UIGestureRecognizerDelegate在我的标题中,并将其包含在内viewDidLoad:
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:swipeLeft];
Run Code Online (Sandbox Code Playgroud)
我的swipeLeft方法如下所示:
-(void)didSwipe:(UISwipeGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateEnded)
{
CGPoint swipeLocation = [recognizer locationInView:self.tableView];
NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLocation];
NSDictionary *clip = [self.clips objectAtIndex:swipedIndexPath.row];
NSLog(@"Swiped!");
}
}
Run Code Online (Sandbox Code Playgroud)
它有点工作,但滑动必须非常精确.像几乎不可能精确.
我差点使用UIPanGestureRecognizer来实现它,但不幸的是它与使用全局平移手势识别器(ECSlidingViewController,感兴趣的人)的全局侧抽屉组件不太搭配.
有没有办法解决?任何帮助将不胜感激,因为我一直在谷歌搜索和浏览SO几个小时寻找解决方案.
我正在研究一些涉及响应式砌体布局的东西。我有一个最大宽度为 的容器,960px但会随着浏览器缩小。我的网格项目具有基于百分比的宽度(100%、66.666666etc%、33.33333etc%)。出于某种原因,当我将函数传递给columnWidth选项时,它总是为容器提供高度 0。这就是我实例化 Masonry 的方式。
$(window).load(function() {
var $container;
$container = $("#grid_container");
$container.masonry({
columnWidth: function(containerWidth) {
return containerWidth / 3;
},
itemSelector: ".grid_item",
isFitWidth: true,
isResizable: true,
gutter: 10
});
});
Run Code Online (Sandbox Code Playgroud)
知道为什么要这样做吗?由于我正在使用$(window).load它应该能够很好地计算高度。我在这里错过了一些非常明显的东西吗?是否根本不可能在 Masonry 中使用百分比列宽?