我需要为a创建一个默认的全局范围 模型 </跨度> 使用newQuery()方法。
Laravel文档说在Eloquent中可以使用匿名函数对WHERE条件进行分组:
DB (‘foreign_id’,MyClass :: $ id) - &gt; orWhere(‘role’,‘admin’); }); }
我收到了502 Bad Gateway错误!我能弄明白如何做的唯一方法 复合 </跨度> 该方法中的位置是通过执行原始查询
你需要全球范围。
这是一个基本示例(更多信息浏览器 SoftDeletingScope 和 SoftDeletingTrait 附带框架):
SoftDeletingScope
SoftDeletingTrait
// Model class PopularUser extends User { protected $table = 'users'; public static function boot() { parent::boot(); static::addGlobalScope(new PopularUserScope); } } // Scope use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\ScopeInterface; class PopularUserScope implements ScopeInterface { public function apply(Builder $builder) { $builder->where('votes', '>', 100) ->where('title', '<>', 'Admin'); } public function remove(Builder $builder) { // you don't need this in your case } }