首页 > 解决方案 > laravel 8,如何使用 post 方法显示来自 FORM 的数据?

问题描述

我的路线:

Route::resource('/posts',PostsControllerWithAll::class);

我的表格: 我尝试从这个表格中读取给定的数据

<form method="POST" action="{{ action('PostsControllerWithAll@store') }}">
 @csrf
   <input type="text" name="title" placeholder="enter title">
   <input type="submit" name="submit">
</form>

我的控制器:

public function create()
{
    return view("posts.create");

}

public function store(Request $request)
   {
        return $request->all();
   }

这是我的路线清单

路线列表图片,请查看链接图片

标签: phphttp-postlaravel-8

解决方案


尝试使用命名路线,就像您在打印屏幕上显示的那样。

  <form method="POST" action="{{ action('posts.store') }}">...</form>

要验证存储方法上的字段值,请使用 dd($request->all()) 这转储变量并死掉,很高兴看到预期的结果。


推荐阅读