public function dashboard(Request $request) { $stat = new \Stdclass(); $stat->num_ads = Ad::count(); $stat->num_promo_ads = Ad::where('ad_promo', 1)->count(); $stat->users = User::count(); $stat->reports = AdReport::count(); //get last 10 days ads $ads_by_date = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m-%d') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->ads_by_date = []; if (!empty($ads_by_date)) { $stat->ads_by_date = array_reverse($ads_by_date); } //get last 10 promo days ads $promo_ads_by_date = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m-%d') AS date_formated"))->where('ad_promo', 1)->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->promo_ads_by_date = []; if (!empty($promo_ads_by_date)) { $stat->promo_ads_by_date = array_reverse($promo_ads_by_date); } //get last 10 months ads $ads_by_month = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y-%m') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->ads_by_month = []; if (!empty($ads_by_month)) { $stat->ads_by_month = array_reverse($ads_by_month); } //get last 10 years ads $ads_by_year = Ad::select(DB::raw("count(ad_id) AS ad_count, DATE_FORMAT(ad_publish_date, '%Y') AS date_formated"))->groupBy('date_formated')->orderBy('date_formated', 'desc')->take(10)->get()->toArray(); $stat->ads_by_year = []; if (!empty($ads_by_year)) { $stat->ads_by_year = array_reverse($ads_by_year); } return view('admin.dashboard.dashboard', ['stat' => $stat]); }
public function delete(Request $request) { //locations to be deleted $data = []; //check for single delete if (isset($request->id)) { $data[] = $request->id; } //check for mass delete if no single delete if (empty($data)) { $data = $request->input('report_id'); } //delete if (!empty($data)) { AdReport::destroy($data); //clear cache, set message, redirect to list Cache::flush(); session()->flash('message', trans('admin_common.Report deleted')); return redirect(url('admin/report')); } //nothing for deletion set message and redirect session()->flash('message', trans('admin_common.Nothing for deletion')); return redirect(url('admin/report')); }
public function axreportad(Request $request) { $ret = array('code' => 400); parse_str($request->form_data, $form_data); if (isset($form_data['report_ad_id']) && is_numeric($form_data['report_ad_id']) && isset($form_data['report_radio']) && is_numeric($form_data['report_radio'])) { $ad_report = new AdReport(); $ad_report->report_ad_id = $form_data['report_ad_id']; $ad_report->report_type_id = $form_data['report_radio']; $ad_report->report_info = nl2br($form_data['report_more_info']); $ad_report->report_date = date('Y-m-d H:i:s'); if (Auth::check()) { $ad_report->report_user_id = $request->user()->user_id; } try { $ad_report->save(); $ret['code'] = 200; $ret['message'] = 'Thanks, The report is send.'; } catch (\Exception $e) { $ret['message'] = 'Ups, something is wrong, please try again.'; } } else { $ret['message'] = 'Ups, something is wrong, please try again.'; } echo json_encode($ret); }