I created a global query scope in one of my models. The scope is called "waiting", and it is used to indicate that a follow resource is waiting to be approved.
I separated the approved resources in one specific view wich is associated to a controller. Then I created another controller wich will display all the "waiting" resources.
I know that I can disable the global scope temporarily, but there's a way to disable the global query scope in all methods of my controller. Later I'll need to implement more methods?
You can create your model instance without the global scope inside the controllers constructor and use it like
class SomeController extends Controller
{
protected $model;
public function __construct()
{
$this->model = Model::withoutGlobalScope('waiting');
}
public function index()
{
$this->model->get();
}
}
I liked the two solutions, but I liked the @srinathdudi solution.
Simply adds a protected variable in the controllers that needs to disable the global query scope.