Laravel模型插入/删除/获取始终具有固定的位置

I want to have all of my Models to fetch/insert/update always with a fixed WHERE.

Like: where( 'site_id', '=', '1')

Without me having to go to all of my queries and change everything.

How can I do this?

Thanks

You just need to create a BaseModel:

class BaseModel extends Eloquent {

    public function newQuery()
    {
        $query = parent::newQuery();

        $query->where('site_id', 1);

        return $query;
    }

}

Extends all your models from it

class Post extends BaseModel {

}

And all your queries will have that site_id filter on it.