1

I have a function on my model that check active status in equipment_station table,

originally it only checked one status, now i need to pass a parameter to the model with active or inactive values, I've tried this with no success.

controller: controller query

model : model image

How can i change the parameter in the model, I send status from controller as inactive or active.

thanks in advance

1
  • could you paste the code instead of upload a screenshot Commented Jun 9, 2017 at 1:10

2 Answers 2

1

You could you query scope

public function scopeActive($query, $active)
{
   return $query->where('active', $active);
}

then you can call it in your model

Estacion::active(true)->get();
Sign up to request clarification or add additional context in comments.

Comments

1

You could Constraint Eager Loading by specifying additional query constraints for the eager loading

$historial_estaction = 
Estacion::where('estacion.id', $id)
   ->whereHas('equipos', function($query) use ($estado1) {
        $query->where('equipo_estacion.estado', $estado1);
    })->with(['equipos' => function ($query) use ($estado1) {
        $query->where('estado', $estado1);
    }])->get();

Model:

public function equipos()
{
    return $this->belongsToMany('App\Equipo')
                ->withPivot('estado')
                ->withTimestamps();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.