3

hey Guys i am using resources route for posts i have store method in my PostsCOntroller controller that i created.

my form is

<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>

whenever i clikc submit i get this error

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException thrown with message

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

5
  • Have you declared a post route in your routes.php/web.php depending on your laravel version? Commented Sep 24, 2017 at 16:29
  • yeah i have actually Route::resource('posts', 'PostsController'); Commented Sep 24, 2017 at 16:29
  • how about trying the url form of form then? eg: {!! Form::open(['url' => 'posts']) !!} Don't forget to close the form with {!! Form::close() !!} Commented Sep 24, 2017 at 16:32
  • i did not wanted to do that. i tried url form and it works but i wanted to make it work without the url version. Commented Sep 24, 2017 at 16:33
  • ok, then can you try Form::open(['action' => 'PostsController@store'']) ? Same as above, close the Form after finishing. Commented Sep 24, 2017 at 16:36

2 Answers 2

4

Your action is wrong. You should use url not action or controller name. Try this:

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

route helper generates url by route name. In your case it will return http://yourdomain/posts

Sign up to request clarification or add additional context in comments.

3 Comments

According to your comment this Route::resource('posts', 'PostsController') should define this route. But it looks like it doesn't. Try php artisan route:list in console and you will see all defined routes with urls and names
try this <form method='POST' action='{{url('posts')}}'>
it gave no error now buy says The page has expired due to inactivity after i press submit button but yes it is redirecting to correct url now.
0
  1. define your route at file web.php

    Route::post('posts', 'PostsController@store')->name('posts.store');

  2. update your view template to

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.