0

Hi I'm saving information from blade. The form goes to store function. After saving data I have to send push info using GCM. But this function can not return to view. How can solve this?

  public function store(Request $request)
   {
    $request->validate([
        'title_uz' => 'required',        
        'desc_uz' => 'required',
        'url_uz' => 'required',
        'company_id' => 'required',
    ]);
      News::create($request->all());
      $this->versionUpdate();
      $this->sendpush($request);
     }

And next function

public function sendpush (Request $request)
{
    $fcmUrl = 'https://fcm.googleapis.com/fcm/send';
    $notification = [
        'title' => $request->title_uz,
        'text' => $request->desc_uz,
    ];

    ***** here is some functions *******

    $result = curl_exec($ch);
    curl_close($ch);

    $result_to = json_decode($result);

    if ($result_to === null) {
        return redirect()->route('news.index')
            ->with('success','DIQQAT!!! Yangilik qo`shildi ammo  push-xabar yuborilmadidi.');
    }
    else {
        return redirect()->route('news.index')
            ->with('success','Yangilik qo`shildi  va push-xabar muvoffaqiyatli yuborildi.');
    }
}

$result_to returns value but the browser holds at blank screen. It seems the store function holds at the end.

2
  • You are not returning anything at this line $this->sendpush($request); Commented Dec 3, 2020 at 5:40
  • 1
    you need to do in master function return $this->sendpush($request); then it will work Commented Dec 3, 2020 at 5:46

2 Answers 2

1

Try this line return $this->sendpush($request);instead of this $this->sendpush($request);

Sign up to request clarification or add additional context in comments.

Comments

0

you have redirect from this method so you can try like these

$result_to = $this->sendpush($request);;
    if ($result_to === null) {
        return redirect()->route('news.index')
            ->with('success','DIQQAT!!! Yangilik qo`shildi ammo  push-xabar yuborilmadidi.');
    }
    else {
        return redirect()->route('news.index')
            ->with('success','Yangilik qo`shildi  va push-xabar muvoffaqiyatli yuborildi.');
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.