gpt4 book ai didi

Laravel 存储方法错误

转载 作者:行者123 更新时间:2023-12-04 13:23:07 26 4
gpt4 key购买 nike

嘿伙计们,我正在为帖子使用资源路由,我在我创建的 PostsCOntroller Controller 中有存储方法。

我的表格是

<div class='container-fluid'>
<form method='POST' action='PostsController@store'>
<div class="form-group">
<label for="exampleFormControlInput1">Text Area</label>
<input type="text" class="form-control"
id="exampleFormControlInput1" placeholder="Enter Title">
</div>

<div class="form-group">
<label for="exampleFormControlTextarea1">Body</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="5" placeholder="Enter Body"></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>

</form>

每当我点击提交时,我都会收到此错误

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 抛出消息

Stacktrace:

#26 Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:255

#25 Illuminate\Routing\RouteCollection:methodNotAllowed in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:242

#24 Illuminate\Routing\RouteCollection:getRouteForMethods in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php:176

#23 Illuminate\Routing\RouteCollection:match in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Router.php:599

#22 Illuminate\Routing\Router:findRoute in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Router.php:578

#21 Illuminate\Routing\Router:dispatchToRoute in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Router.php:564

#20 Illuminate\Routing\Router:dispatch in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176

#19 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30

#18 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in E:\XAMPP\htdocs\lsapp\vendor\fideloper\proxy\src\TrustProxies.php:56

#17 Fideloper\Proxy\TrustProxies:handle in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149

#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53

#15 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:30

#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149

#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53

#12 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:30

#11 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149

#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53

#9 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27

#8 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149

#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53

#6 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php:46

#5 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:149

#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53

#3 Illuminate\Routing\Pipeline:Illuminate\Routing{closure} in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:102

#2 Illuminate\Pipeline\Pipeline:then in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151

#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in E:\XAMPP\htdocs\lsapp\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116

#0 Illuminate\Foundation\Http\Kernel:handle in E:\XAMPP\htdocs\lsapp\public\index.php:55

最佳答案

你的行为是错误的。您应该使用 url 而不是操作或 Controller 名称。试试这个:

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

route 帮助程序通过路由名称生成 url。在您的情况下,它将返回 http://yourdomain/posts

关于Laravel 存储方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46392272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com