1

I Created a form in my view form.blade.php file (resources/views/form.blade.php)

<form method="POST" action="{{route('bulksend')}}">
     <label>Title</label>
     <input type="text" hint="Title" name="title">
     <br>
     <label>Body</label>
     <input type="text" hint="Body" name="body">
     <br>
     <label>Image URL</label>
     <input type="text" hint="Image URL" name="img">
     <br>
     <label>ID</label>
     <input type="text" hint="Image URL" name="id">
     <br>
     <input type="submit"/>
 </form>

I created a web route (routes/web.php)

Route::get('form', function () {
     return view('form');
 });

 Route::post('send','MyController@bulksend')->name('bulksend');

I Created a controller named MyController in app/Http/Controller and I added this function to it.

    public function bulksend(Request $req){
         $url = 'https://fcm.googleapis.com/fcm/send';
         $dataArr = array('click_action' => 'FLUTTER_NOTIFICATION_CLICK', 'id' => $req->id,'status'=>"done");
         $notification = array('title' =>$req->title, 'text' => $req->body, 'image'=> $req->img, 'sound' => 'default', 'badge' => '1',);
         $arrayToSend = array('to' => "/topics/all", 'notification' => $notification, 'data' => $dataArr, 'priority'=>'high');
         $fields = json_encode ($arrayToSend);
         $headers = array (
             'Authorization: key=' . "YOUR_FCM_KEY",
             'Content-Type: application/json'
         );
    
         $ch = curl_init ();
         curl_setopt ( $ch, CURLOPT_URL, $url );
         curl_setopt ( $ch, CURLOPT_POST, true );
         curl_setopt ( $ch, CURLOPT_HTTPHEADER, $headers );
         curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );
         curl_setopt ( $ch, CURLOPT_POSTFIELDS, $fields );
    
         $result = curl_exec ( $ch );
         //var_dump($result);
         curl_close ( $ch );
         return $result;
    
     }

web.php

 Route::get('form', function () {
        return view('form');
    });

 Route::post('send','NotificationController@bulksend')->name('bulksend');

http://127.0.0.1:8000/form The form is created in this link and when I press the submit button in this form, the following error comes up:

Symfony \ Component \ HttpKernel \ Exception \ 
MethodNotAllowedHttpException
No message



protected function methodNotAllowed(array $others)
    {
        throw new MethodNotAllowedHttpException($others);
    }

 

0 Answers0