如何解决使用 Laravel,我在通知颤振应用程序时收到以下错误
我在我的视图 form.blade.PHP 文件 (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>
Route::get('form',function () {
return view('form');
});
Route::post('send','MyController@bulksend')->name('bulksend');
我在 app/Http/Controller 中创建了一个名为 MyController 的控制器,并在其中添加了这个函数。
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,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 表单是在此链接中创建的,当我按下此表单中的提交按钮时,出现以下错误:
Symfony \ Component \ HttpKernel \ Exception \
MethodNotAllowedHttpException
No message
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。