“对于此路线不支持GET方法。支持的方法:发布。
我正在尝试添加新帖子,但是每当我提交时,我都会收到上述错误消息。
这是路线:
Route::get('/p/create' , [App\Http\Controllers\PostsController::class, 'create']);
Route::post('/p' , [App\Http\Controllers\PostsController::class, 'store']);
这是我的控制器:
{
public function create(){
return view('posts.create');
}
public function store(){
$data = request()->validate([
'caption'=>'required',
'image'=>'required|image',
]);
$imagePath =request('image')->store('uploads' ,'public');
// auth()->user()->posts()->create($data);
auth()->users()->posts()->create([
'caption' => $data['caption'],
'image' => $imagePath,
]);
//dd(request()->all() );
return redirect('/profile/' . auth()->user()->id);
}
}
有人遇到了同样的问题吗?
I'm trying to add a new Post but whenever i submit i get the above error message.
This is Route:
Route::get('/p/create' , [App\Http\Controllers\PostsController::class, 'create']);
Route::post('/p' , [App\Http\Controllers\PostsController::class, 'store']);
and this is my controller:
{
public function create(){
return view('posts.create');
}
public function store(){
$data = request()->validate([
'caption'=>'required',
'image'=>'required|image',
]);
$imagePath =request('image')->store('uploads' ,'public');
// auth()->user()->posts()->create($data);
auth()->users()->posts()->create([
'caption' => $data['caption'],
'image' => $imagePath,
]);
//dd(request()->all() );
return redirect('/profile/' . auth()->user()->id);
}
}
Anyone faced the same problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题在您的客户方面。
您应该使用邮政方法提交表格。
例如,此表格发送帖子方法:
Your problem is in your client side .
You should submit your form with post method not get.
for example this form send post method :
尝试将商店方法修改为
Try Modifying the store method to