Mikegk
6 months ago

Chain-break Eloquent methods

Posted 6 months ago by Mikegk

Hi guys,

I just wanted to create an Eloquent Query and some parts of it should just be applied to the filters if certain parameters are set

$model = MyModel::with('tasks','projects')
->where('active',1);
if($param1){
$model->where('something',$param1);
}

$model->get();

Sadly that doesn't work. I also can neither use MyModel->where(...) nor MyModel::where(...) to continue...

Any ideas?

Please sign in or create an account to participate in this conversation.