url = 'member'; parent::__construct(); } public function showMember(Request $request, $department, $membertype = null) { $model = User::select('users.*') ->addSelect('tags1.name as title') ->join('user_tag as user_tag1', function($join){ $join->on('user_tag1.user_id', 'users.id'); }) ->join('tags as tags1', function($join) use($membertype, $department){ $join->on('user_tag1.tag_id', 'tags1.id'); if($department == 'Gesamtwehr') { $join = $join->where('tags1.type', 'mitgliedsart-gesamtwehr'); } else { $join = $join->where('tags1.type', 'mitgliedsart-abteilung'); } if($membertype) { $join = $join->where('tags1.name', $membertype); } }) ->orderBy('tags1.order'); if($department != 'Gesamtwehr') { $model = $model ->addSelect('tags2.name as department') ->join('user_tag as user_tag2', function ($join) { $join->on('user_tag2.user_id', 'users.id'); }) ->join('tags as tags2', function ($join) use ($department) { $join->on('user_tag2.tag_id', 'tags2.id') ->where('tags2.type', 'abteilung') ->where('tags2.name', $department); }); } $model = $model->get(); $model->each(function($m) use($department){ $m->type = 'benutzer'; if($department == 'Gesamtwehr') { $m->department = 'Gesamtwehr'; } }); $this->prepareModel2($model); $model->isMainPost = true; $view = view('inc.views.members'); $view->with('config', array()); $view->with('models', $model); $view->with('url', $this->route); return $view; } }