10 months ago

How can I filter by relationship?

Posted 10 months ago by cac

I have a model called Company which may have many Vacancy models. And this Vacancy has one PipeVacancy. So my question is how can I filter the query to bring me only the Vacancies that already have a PipeVacancy. I was think maybe I could achieve this with scoped queries but I had no idea how to write that piece of code. What I want with this is to avoid that inner @if.

                 @foreach($company->vacancies as $vacancy)
                                            <div class="row">
                                                <div class="col-md-8">
                                                <div class="col-md-4">
                                                    <a href="{{route('myroute',$vacancy->id)}}">
                                                        <button class="btn btn-sm btn-success"

Any tips?

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