Global scope model

Submitted by GesJeremie - 2 years ago

Sometimes you must always use a global scope when you perform a query from your model.

<?php

class Comment extends Eloquent {

	public function newQuery()
	{
		return parent::newQuery()->where('cat', '=', 6);
	}
    
    // Now when you will perform a query like :
    // Comment::count()
    // Your scope defined in the newQuery will be used
}
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks