public function deleteNews($news_id) { try { News::findOrFail($news_id)->delete(); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { Session::flash('error_msg', 'Unable to find News item to delete'); return Redirect::back(); } Session::flash('success_msg', 'News deleted successfully'); return Redirect::back(); }
public function index() { $this->data['notifications'] = Notifications::getActiveNotifications(); $this->data['archived_notifications'] = Notifications::getArchivedNotifications(); $this->data['news'] = News::orderBy('created_at', 'DESC')->get(); if (Auth::user()->isAdmin()) { $past_hr = \Carbon\Carbon::now()->subHour(); $today = \Carbon\Carbon::now()->subDay(); $this_week = \Carbon\Carbon::now()->subWeek(); $this_month = \Carbon\Carbon::now()->subMonth(); $this->data['users_past_hr'] = DB::table('users')->where('created_at', '>', $past_hr)->count(); $this->data['users_today'] = DB::table('users')->where('created_at', '>', $today)->count(); $this->data['users_this_week'] = DB::table('users')->where('created_at', '>', $this_week)->count(); $this->data['users_this_month'] = DB::table('users')->where('created_at', '>', $this_month)->count(); $this->data['users_total'] = sizeof(DB::table('users')->get()); } return View::make('backend.index', $this->data); }
public function postNewsUpdate($news_id) { if (sizeof(DB::table('news')->where('slug', Str::slug(Input::get('title')))->where('id', '!=', $news_id)->get()) > 0) { Session::flash('error_msg', 'News with same title already exists'); return Redirect::back(); } try { $news = News::findOrFail($news_id); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { Session::flash('error_msg', 'Unable to find News item to update'); return Redirect::back(); } $news->title = Input::get('title'); $news->slug = Str::slug(Input::get('title')); $news->description = Input::get('description'); $news->status = Input::get('status'); $news->save(); Session::flash('success_msg', 'News updated successfully'); return Redirect::to('/admin/news/all'); }