/** * Store a newly created Post in storage. * * @param CreatePostRequest $request * * @return Response */ public function store(CreatePostRequest $request) { $input = $request->all(); $input['objectId'] = 'Post' . str_random(10); if ($request->file('image')) { $image = $this->uploadImage($request->file('image'), '/posts_photo/'); $input['image'] = $image['resize_url'][0]; } if ($request->file("audioFile")) { $input['audioFile'] = $this->uploadAudio($request->file('audioFile'), '/posts_audio/'); } $post = $this->postRepository->create($input); $device_list = []; $gcm = Gcm::all(); foreach ($gcm as $key => $value) { $device_list[] = PushNotification::Device($value->reg_id); } $message['title'] = $input['title']; $message['message'] = $input['content']; $devices = PushNotification::DeviceCollection($device_list); $message = PushNotification::Message(json_encode($message), array()); $collection = PushNotification::app('appNameAndroid')->to($devices)->send($message); Flash::success('Post saved successfully.'); return redirect(route('posts.index')); }
/** * Store a newly created GcmMessage in storage. * * @param CreateGcmMessageRequest $request * * @return Response */ public function store(CreateGcmMessageRequest $request) { $input = $request->all(); $gcmMessage = $this->gcmMessageRepository->create($input); if ($request->file('image')) { $uploadImage = $this->uploadImage($request->file('image'), '/gcms_photo/'); $input['image'] = $uploadImage['resize_url'][0]; } $device_list = []; if ($input['user_id'] != 'All') { $gcm = Gcm::where('user_id', $input['user_id'])->first(); $device_list[] = PushNotification::Device($gcm->reg_id); } else { $gcm = Gcm::all(); foreach ($gcm as $key => $value) { $device_list[] = PushNotification::Device($value->reg_id); } } $devices = PushNotification::DeviceCollection($device_list); $message = PushNotification::Message(json_encode($input), array()); $collection = PushNotification::app('appNameAndroid')->to($devices)->send($message); Flash::success('GcmMessage saved successfully.'); return redirect(route('gcmMessages.index')); }
/** * Store a newly created Post in storage. * POST /posts * * @param Request $request * * @return Response */ public function store(Request $request) { if (sizeof(Post::$rules) > 0) { $this->validateRequestOrFail($request, Post::$rules); } $input = $request->all(); $message['message'] = isset($input['content']) && $input['content'] ? $input['content'] : $input['content_mm']; $input['objectId'] = 'Post' . str_random(10); $input['postUploadNameMM'] = $input["postUploadName"]; $input['content'] = isset($input['content']) && $input['content'] ? $input['content'] : 'This content is currently only available in Myanmar language.'; $input['content_mm'] = isset($input['content_mm']) && $input['content_mm'] ? $input['content_mm'] : 'အဂၤလိပ္ ဘာသာစကားၿဖင့္သာ လက္ရွိတြင္ ေပးပိုု ့ထားပါသည္။'; $posts = $this->postRepository->create($input); if ($posts->category_id == 'MqLh2pZShc' || $posts->category_id == 'DuXAXGFbEe') { $device_list = []; $gcm = Gcm::all(); foreach ($gcm as $key => $value) { $device_list[] = PushNotification::Device($value->reg_id); } if ($posts->category_id == 'MqLh2pZShc') { $message['title'] = isset($input['content']) ? 'Market' : 'အေရာင္း / အ၀ယ္'; } else { $message['title'] = isset($input['content']) ? 'Q&A' : 'အေမးအေျဖ'; } $devices = PushNotification::DeviceCollection($device_list); $message = PushNotification::Message(json_encode($message), array()); $collection = PushNotification::app('appNameAndroid')->to($devices)->send($message); } return $this->sendResponse($posts->toArray(), "Post saved successfully"); }