“对于此路线不支持GET方法。支持的方法:发布。

发布于 2025-01-24 00:28:52 字数 989 浏览 4 评论 0原文

我正在尝试添加新帖子,但是每当我提交时,我都会收到上述错误消息。

这是路线

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

战皆罪 2025-01-31 00:28:52

您的问题在您的客户方面。

您应该使用邮政方法提交表格。
例如,此表格发送帖子方法:

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

Your problem is in your client side .

You should submit your form with post method not get.
for example this form send post method :

<form action="{{route('example_route')}}" method='post' >
//some html here
</form>
大姐,你呐 2025-01-31 00:28:52

尝试将商店方法修改为

public function store(Request $request){

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

Try Modifying the store method to

public function store(Request $request){

        $data = $request->validate([
            'caption'=>'required',
            'image'=>'required|image',
        ]);
//...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文