希望能够搜索特定的费用,当作为Coro委员会执行搜索时,会出现属于该职位的所有成员。
视觉代码:
@foreach ($ members as $ member)
{{$ member-> mName}}
{{$ member-> mapellido}}
{{$ member-> mSector}}
{{$ member-> stage-> eType}}
@if (empty ($ member-> formations-> fType))
@else
{{$ member-> formaciones-> fType}}
@endif
@foreach ($ member-> charges as $ charge)
{{$ charge-> cType}}
@endforeach
@endforeach
有一个教区成员和职位表,其中有很多。中间表的名称为:cargo_membership_parish
以下内容在控制器中。
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'));
}
SCOPEQUERY的制作方法如下:
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) {
}
如果您有关于如何执行与多对多费用有关的范围查询的想法,那将非常有帮助。谢谢
答案 0 :(得分:0)
您的问题有点让我感到困惑,但是如果我没有正确地回答您,那么您希望通过关系来过滤结果。因此,您可以使用int stateStream(int[] arr) {
return IntStream.range(0, arr.length - 1)
.filter(i -> arr[i + 1] - arr[i] > 1) // your condition
.mapToObj(i -> arr[i])
.findFirst() // first such occurrence
.map(i -> i + 1) // to add 1 to the point where the cehck actually failed
.orElse(0); // some default value
}
方法来实现这一目标。
int stateStream(int[] arr) {
List<Integer> list = Arrays.stream(arr)
.boxed().sorted()
.filter(value -> value > 0)
.collect(Collectors.toList());
return IntStream.range(0, list.size() - 1)
.filter(i -> list.get(i + 1) - list.get(i) > 1)
.mapToObj(list::get)
.findFirst()
.map(i -> i + 1)
.orElse(0);
}