芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/store.kwesioben.com/app/Http/Controllers/Admin/NotificationController.php
has('search')) { $key = explode(' ', $request['search']); $notifications = Notification::where(function ($q) use ($key) { foreach ($key as $value) { $q->Where('title', 'like', "%{$value}%"); } }); $query_param = ['search' => $request['search']]; }else{ $notifications = new Notification(); } $notifications = $notifications->where('sent_to', 'customer')->latest()->paginate(Helpers::pagination_limit())->appends($query_param); return view('admin-views.notification.index', compact('notifications','search')); } public function store(Request $request) { $request->validate([ 'title' => 'required', 'description' => 'required' ], [ 'title.required' => 'title is required!', ]); $notification = new Notification; $notification->title = $request->title; $notification->description = $request->description; if ($request->has('image')) { $notification->image = ImageManager::upload('notification/', 'png', $request->file('image')); } else { $notification->image = 'null'; } $notification->status = 1; $notification->notification_count = 1; $notification->save(); try { Helpers::send_push_notif_to_topic($notification); } catch (\Exception $e) { Toastr::warning(translate('push_notification_failed')); } Toastr::success(translate('notification_sent_successfully')); return back(); } public function edit($id) { $notification = Notification::find($id); return view('admin-views.notification.edit', compact('notification')); } public function update(Request $request, $id) { $request->validate([ 'title' => 'required', 'description' => 'required', ], [ 'title.required' => 'title is required!', ]); $notification = Notification::find($id); $notification->title = $request->title; $notification->description = $request->description; $notification->image = $request->has('image')? ImageManager::update('notification/', $notification->image, 'png', $request->file('image')):$notification->image; $notification->save(); Toastr::success(translate('notification_updated_successfully')); return redirect('/admin/notification/add-new'); } public function status(Request $request) { if ($request->ajax()) { $notification = Notification::find($request->id); $notification->status = $request->status; $notification->save(); $data = $request->status; return response()->json($data); } } public function resendNotification(Request $request){ $notification = Notification::find($request->id); $data = array(); try { Helpers::send_push_notif_to_topic($notification); $notification->notification_count += 1; $notification->save(); $data['success'] = true; $data['message'] = translate("push_notification_successfully"); } catch (\Exception $e) { $data['success'] = false; $data['message'] = translate("push_notification_failed"); } return $data; } public function delete(Request $request) { $notification = Notification::find($request->id); ImageManager::delete('/notification/' . $notification['image']); $notification->delete(); return response()->json(); } public function push_notification() { return view('admin-views.notification.push-notification'); } }