2016-06-17 4 views
1

を変更せずに流暢に使用できるのは、私はかなり単純なテーブルを持っているし、どこかに私のLaravelのインストールで私が入れたとしましょう:は、どのように私は最初の変数

$model = DB::connection('second')->table('models');

後、私のような何かをしたいの:

echo $model->where('column', 1)->count();

echo $model->where('another_column', 0)->count();

$modelは既に他のものなので、2番目の機能は動作しません。その連鎖を使って何かをしなければならないのですが、同じことをどうすれば変更できますか?$model?あなたが$model = $model->where('another_column', 0)->count();を行うとしたら

$baseQuery = DB::connection('second')->table('models'); 

$countQuery = clone $baseQuery; 
$countQuery->where('column', 1)->count(); 

$otherQuery = clone $baseQuery; 
$otherQuery->where('another_column', 0)->count(); 

答えて

4

あなたがPHPのcloneを使用して試すことができます。

もちろん、$modelを変更したくない場合は、$modelb = $model->where('another_column', 0)->count();とすることができます。

関連する問題