public function getBlogs($id)
 {
     $tag = $this->tagRepository->findById($id);
     $tags = $this->tagRepository->getBlogTags();
     $posts = $tag->blogs()->paginate(5);
     $this->title = $tag->name;
     $this->render('site.tags.blogs', compact('posts', 'tag', 'tags'));
 }
 /**
  * Returns all the blog posts.
  *
  * @return View
  */
 public function index()
 {
     // Get all the blog posts
     $this->title = trans('word.blog');
     $posts = $this->blogRepository->getAllPaginated(['category', 'photos', 'author']);
     $categories = $this->categoryRepository->getPostCategories()->get();
     $tags = $this->tagRepository->getBlogTags();
     // Show the page
     $this->render('site.blog.index', compact('posts', 'categories', 'tags'));
 }
 /**
  * Update the specified resource in storage.
  * @param $id
  * @internal param $post
  * @return Response
  */
 public function update($id)
 {
     $record = $this->blogRepository->findById($id);
     $val = $this->blogRepository->getEditForm($id);
     if (!$val->isValid()) {
         return Redirect::back()->with('errors', $val->getErrors())->withInput();
     }
     if (!$this->blogRepository->update($id, $val->getInputData())) {
         return Redirect::back()->with('errors', $this->blogRepository->errors())->withInput();
     }
     $tags = is_array(Input::get('tags')) ? array_filter(Input::get('tags')) : [];
     $this->tagRepository->attachTags($record, $tags);
     return Redirect::action('AdminBlogsController@edit', $id)->with('success', 'Updated');
 }
 public function index()
 {
     $perPage = 10;
     $expiredEvents = $this->eventRepository->getPastEvents($perPage);
     //find countries,authors,and categories to display in search form
     $countries = [0 => trans('word.choose_country')] + $this->countryRepository->getAll()->lists('name_' . getLocale(), 'id');
     $categories = [0 => trans('word.choose_category')] + $this->categoryRepository->getEventCategories()->lists('name_' . getLocale(), 'id');
     $authors = [0 => trans('word.choose_author')] + $this->userRepository->getRoleByName('author')->lists('name_' . getLocale(), 'id');
     // find selected form values
     $search = trim(Input::get('search'));
     $category = Request::get('category');
     $author = Request::get('author');
     $country = Request::get('country');
     $expired = Request::get('past');
     $this->title = trans('word.events');
     // if the form is selected
     // perform search
     if (!empty($search) || !empty($category) || !empty($author) || !empty($country)) {
         $events = $this->eventRepository->getAll()->where(function ($query) use($search, $category, $author, $country) {
             if (!empty($search)) {
                 $query->where('title_ar', 'LIKE', "%{$search}%")->orWhere('title_en', 'LIKE', "%{$search}%");
             }
             if (!empty($category)) {
                 $query->where('category_id', $category);
             }
             if (!empty($author)) {
                 $query->where('user_id', $author);
             }
             if (!empty($country)) {
                 $locations = $this->countryRepository->findById($country)->locations()->lists('id');
                 $query->whereIn('location_id', $locations);
             }
         })->orderBy('date_start', 'ASC')->orderBy('created_at', 'ASC')->paginate($perPage);
     } elseif (isset($expired) && $expired == 'true') {
         // Past Events
         $this->title = trans('word.expired_events');
         $events = $expiredEvents;
     } else {
         $events = $this->eventRepository->getNonExpiredEvents($perPage);
     }
     $eventCategories = $this->categoryRepository->getEventCategories()->get();
     $tags = $this->tagRepository->getEventTags();
     $this->render('site.events.index', compact('events', 'authors', 'categories', 'countries', 'search', 'category', 'author', 'country', 'eventCategories', 'tags', 'expiredEvents'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int $id
  * @return Response
  */
 public function update($id)
 {
     $event = $this->eventRepository->findById($id);
     $val = $this->eventRepository->getEditForm($id);
     if (!$val->isValid()) {
         return Redirect::back()->with('errors', $val->getErrors())->withInput();
     }
     if (Input::get('date_start') > Input::get('date_end')) {
         return Redirect::back()->with('error', 'Event Date Start Cannot be greater than Event End Date');
     }
     if (!$this->eventRepository->update($id, $val->getInputData())) {
         return Redirect::back()->with('errors', $this->eventRepository->errors())->withInput();
     }
     // update the tags
     $tags = is_array(Input::get('tags')) ? array_filter(Input::get('tags')) : [];
     $this->tagRepository->attachTags($event, $tags);
     return Redirect::action('AdminEventsController@index')->with('success', 'Updated');
     //        return Redirect::action('AdminEventsController@edit',$event->id)->with('success', 'Updated');
 }