/** * @return array */ public function getVenueOptions() { $raw = Venue::find()->orderBy('VenueType_id')->all(); $arr = array(); foreach ($raw as $row) { $venueType = \app\models\VenueType::getVenueTypeById($row['VenueType_id']); $arr[$row['id']] = $venueType . ' - ' . $row['name']; } return $arr; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Venue::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->joinWith('venueType'); $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'location', $this->location])->andFilterWhere(['like', 'map', $this->map])->andFilterWhere(['like', 'floorPlan', $this->floorPlan])->andFilterWhere(['like', 'venueType.name', $this->VenueType_id]); return $dataProvider; }
/** * Remove the specified resource from storage. * * @param int $id * * @return mixed */ public function destroy($id) { $canBeDeleted = empty(Venue::find($id)->fixtures->toArray()); if ($canBeDeleted) { Venue::destroy($id); \Flash::success('Venue deleted!'); } else { \Flash::error('Cannot delete because they are existing fixtures at this venue.'); } return redirect('admin/data-management/venues'); }
/** * Remove the specified resource from storage. * * @param int $id * * @param Request $request * * @return \Illuminate\Http\Response */ public function destroy($id, Request $request) { if ($request->user()->can('admin') || $request->user()->can('super')) { $venue = Venue::find($id); DB::transaction(function () use($venue) { $venue->admins()->detach(auth()->user()); $venue->delete(); session()->flash('message', ['warning', "{$venue->name} Successfully Deleted!"]); }); return redirect(action('VenueController@index')); } session()->flash('message', ['danger', 'Unauthorized!']); return redirect(action('VenueController@index')); }