"The GET method is not supported for this route. Supported methods: POST ."



我试图添加一个新的帖子,但每当我提交我得到上述错误信息。

This isRoute:

Route::get('/p/create' , [AppHttpControllersPostsController::class, 'create']);
Route::post('/p' , [AppHttpControllersPostsController::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);
}
}

有人遇到同样的问题吗?

问题出在客户端。

你应该用post方法提交表单,而不是get方法。例如:

<form action="{{route('example_route')}}" method='post' >
//some html here
</form>

尝试将存储方法修改为

public function store(Request $request){
$data = $request->validate([
'caption'=>'required',
'image'=>'required|image',
]);
//...

相关内容

  • 没有找到相关文章

最新更新