vendredi 28 décembre 2018

how to perform an advanced search with scopequery

It is desired to be able to search for a specific charge, where when performing the search as the Coro Commission, all the members that belong to that position appear.

The code of sight:

@foreach ($ members as $ member)

                
                
                
                
                @if (empty ($ member-> formations-> fType))

                @else
               
               @endif

                @foreach ($ member-> charges as $ charge)

                        

                  @endforeach

            @endforeach

There is a table of parish members and positions, with many to many among them. The intermediate table has the name: cargo_membership_parish

The following is in the controller.

public function filters (Request $ request) {

  $ sector = $ request-> input ('sector');
  $ form = $ request-> formacion_id;
  $ stages = Stage :: all ();
  $ formation = Training :: all ();
  $ stage = $ request-> stage_id;
  $ charge = Charge :: all ();
  $ m_cargo = $ request-> car;
    $ members = Member_Parroquial :: orderBy ('id', 'DESC') -> sector ($ sector) -> stage ($ stage) -> training ($ form) -> get ();

  return view ('member.member_index', compact ('stages', 'formation', 'members', 'position'));

}

The SCOPEQUERY have been made in the following way:

public function scopeEtapa ($ query, $ stage) {

    if ($ stage) {

        return $ query-> where ('stage_id', 'LIKE', "% $ stage%");
    }
}

public function scopeFormation ($ query, $ form) {

    if ($ form) {
        return $ query-> where ('training_id', 'LIKE', "% $ form%");

    }
}

public function scopeCharge ($ query, $ charge) {

}

If you have an idea of ​​how to perform the scope query for charges in relation to many to many, it would be very helpful. Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire