laravel - 防止数据库播种的全局范围
问题描述
我正在使用 Laravel spark,并且我通过使用在 trait 中实现的范围来限制团队对模型的访问
namespace App\Scopes;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class TeamScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$builder->where('team_id', '=',Auth()->user()->currentTeam->id );
}
}
我的问题是,当我运行数据库播种机时,它失败了,因为没有用户可以验证。
播种机没有任何方法可以让我登录特定用户。
有没有办法在播种时禁用全局范围,或任何其他解决方案?
谢谢
解决方案
如果你在种子中调用模型,你可以->withoutGlobalScopes()
先调用
更多关于这里https://laravel.com/docs/5.7/eloquent#query-scopes在“删除全局范围”部分。
推荐阅读
- javascript - ReactJS 和 Material UI makeStyles/useStyles 问题
- algorithm - 矩形可以放在其他矩形内吗?
- python - 如果同一行中有两个href,我怎样才能使用beautifulsoup 只获得一个href?
- python - Python中更精确的直方图
- c# - 如何创建和读取用户设置后可编辑的文本文件?
- excel - VBA 矩阵打印
- android - 带有 ConstraintLayout 和 padding 的 LinearLayout
- haskell - How to pattern-match an intermediate value in Haskell
- java - 我可以在一个 RecycleView 适配器中膨胀两个列表布局吗?
- arrays - 从Controller中的数组获取数据