/** * Display a listing of the resource. * * @return Response */ public function index($areaSlug, $categorySlug = null, $postId = null) { $groups = []; $county = $this->user()->county_id; list($area, $category) = $this->repository->areaCategory($areaSlug, $categorySlug, $county); if (!$area || $categorySlug && !$category) { return abort(404); } if ($this->user()->isTrainer()) { $groups = $this->user()->trainerGroups($area, $category); if ($groups->isEmpty()) { return abort(404); } $groupId = Input::get('g'); $group = $groupId ? Group::findOrFail($groupId) : $groups->first(); } else { if (!($group = $this->user()->groupByAreaCategory($area, $category))) { return abort(404); } } if ($postId) { return $this->show($area, $category, $postId); } $posts = $group->posts; return view('area.news', compact('area', 'category', 'posts', 'groups')); }
/** * @param FIIP\Areas\Area area * @param FIIP\Areas\Category|null $category * @return FIIP\Areas\Group|null */ public function group($area, $category = null) { $query = Group::where('area_id', $area->id); if ($category) { $query->where('category_id', $category->id); } $groups = $query->get(); return $this->user->groups()->whereIn('id', $groups->lists('id'))->first(['id', 'name']); }
private function getGroups() { if ($this->user()->can('add_areas')) { $query = Group::query()->where('county_id', config('app.county')); } else { $query = $this->user()->trainerGroups(); } $query->join('areas', 'area_id', '=', 'areas.id')->leftJoin('area_categories', 'category_id', '=', 'area_categories.id'); return $query->get(['area_groups.id', 'area_groups.name', 'category_id', 'areas.name as area_name', 'area_categories.name as category_name']); }
public function run() { DB::table('area_groups')->truncate(); DB::table('area_trainers')->truncate(); foreach ([1, 2, 3, 4] as $area_id) { $group = Group::create(['area_id' => $area_id, 'name' => 'A']); $group->trainers()->attach(1); $group->trainers()->attach(2); $group = Group::create(['area_id' => $area_id, 'name' => 'B']); $group->trainers()->attach(2); $group = Group::create(['area_id' => $area_id, 'name' => 'C']); $group->trainers()->attach(1); $group->trainers()->attach(2); } }
/** * @param int $userId * @param int $groupId * @return Response */ public function delete($userId, $groupId) { if ((int) $this->user()->county_id === 26) { exit; } $group = Group::findOrFail($groupId, ['id']); if (!in_array($this->userId, $group->trainers()->lists('id'))) { return abort(404); } $user = User::findOrFail($userId, ['id']); $user->groups()->detach($groupId); if (Request::wantsJson()) { return json(1); } return back(); }
/** * Remove the specified resource from storage. * * @param int $_ * @param int $id * @return Response */ public function destroy($_, $id) { $group = Group::findOrFail($id); $group->delete(); return json(1); //return Redirect::route('admin.areas.edit', $group->area->id)->withDelete(true); }
public function destroy($_, $groupId, $id) { $group = Group::findOrFail($groupId); $group->users()->detach($id); return json(1); }
protected static function boot() { parent::boot(); Group::observe(new GroupObserver()); }
private function getGroups($queryOnly = false) { if ($this->user()->can('add_areas')) { $query = Group::query(); } else { $query = $this->user()->trainerGroups(); } if ($queryOnly) { return $query; } return $query->get(['id', 'name', 'area_id', 'category_id']); }