Laravel-使用范围 [英] Laravel - Using scope

查看:86
本文介绍了Laravel-使用范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用范围来指定我是否不是管理员,然后仅由讲师返回课程.我要尝试做的是,当一名教师登录他们的帐户时,他们只能查看他们指定的课程..我不确定我的查询哪里出错了..它没有抛出错误,所以我知道还没有破..这是一件好事吗?但是我的查询没有显示我需要的结果.感谢您的帮助.谢谢

I am using scope to specify if i am not an admin, then return courses only by instructor. What I am trying to do is when an instructor signs into their account they can only view the course they have been assigned to teach.. I am unsure where i have gone wrong in my query.. it is throwing no errors so i know it has not broke it.. which is a good thing? But my query is not displaying the results I need. I appreciate any help. Thanks

推荐答案

您的讲师关系没有user_id,因为它在数据透视表中.

Your instructor relation doesn't have user_id because it is in your pivot table.

尝试以下内部查询:$q->where('id', Auth::user()->id);

这篇关于Laravel-使用范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆