Written by
laravel-style
on
on
[laravel] 글로벌 스코프 삭제하기
[laravel] 글로벌 스코프 삭제하기
개발/PHP(laravel)
글로벌 스코프란 특정모델에 주어진 쿼리를 실행하기전 범위를 지정해주는 것.(아주 편-리)
*글로벌 스코프를 모델에 할당하려면, 주어진 모델의 boot 메소드를 오버라이딩 하여 addGlobalScope 메소드를 사용해야 합니다:
특정모델에 걸린 글로벌 스코프를 삭제할 일이 생겼다
protected static function boot()
{
parent :: boot ();
// global scope : CompanyScope
static :: addGlobalScope ( new CompanyScope()); //# 회사가 있는 경우 회사 조건 추가
} Model::withoutGlobalScopes ()->get() //모든 글로벌 스코프 삭제
글로벌 스코프를 삭제하지 않으면 쿼리를 실행하기 전에 내가 boot로 지정한 범위에 맞게 데이터를 가져오게된다.
from http://winniee.tistory.com/6 by ccl(A) rewrite - 2020-04-06 11:01:11