how to solve it

Published 1 month ago by fam

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

Route::group(['middleware'=>['web']],function(){

Route::resource('/post', 'PostsController');

{{csrf_field()}}

<input type="text" name="title" placeholder="Enter">
<input type="submit" name="submit">

</form>

public function create() { //

    return view('posts.create');
}


public function store(Request $request)
{
    //
    return $request ->all();
}
Best Answer (As Selected By fam)
Snapey

ok, if you are not using the Form library (and its better that you don't) then your form open should look like this


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

Cronix
Cronix
1 month ago (786,650 XP)

hard to know without seeing your form open tag.

You also don't need to put the route in the web middleware group if your routes are in /routes/web.php. All routes in that file run through the web middleware.

fam

ok this is rout code->

Route::group(['middleware'=>['web']],function(){

Route::resource('/post', 'PostController');

});

fam

and this is postcontroller code ->

public function create() {

    return view('posts.create');
}

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

}
Cronix
Cronix
1 month ago (786,650 XP)

You already posted that. I was asking about your <form> open tag so we can see what url it's pointing to. You're not showing it.

anonymouse703

@fam what sir @cronix implied for is:

  {!! Form::open(['url'=>['post/'], 'method'=>'POST']) !!}
       <input type="text" name="title" placeholder="Enter">
       <input type="submit" name="submit">
   {!!Form:close()!!}

and in your route:

Route::resource('post', '[email protected]');

Use Laravel blade implementation.

fam

fisrt thank u for ur reply but it give me this meg (BadMethodCallException Method App\Http\Controllers\PostsController::[email protected] does not exist.)

NOMGUY
NOMGUY
1 month ago (58,750 XP)

@fam Your form goes like:

 {!! Form::open( ['method' => 'POST', 'route' => 'posts.store'] ) !!}
       <input type="text" name="title" placeholder="Enter">
       <input type="submit" name="submit">
   {!!Form:close()!!}

and route goes like:

Route::group(['middleware'=>['web']],function(){
    Route::resource('/post', 'PostsController');
});
fam

it give men this!!

"Class 'Form' not found"

Snapey
Snapey
1 month ago (1,037,395 XP)

@nomguy You don't need to specify web middleware

@fam routes associated with resource controllers are documented;

https://laravel.com/docs/5.6/controllers#resource-controllers

Snapey
Snapey
1 month ago (1,037,395 XP)

ok, if you are not using the Form library (and its better that you don't) then your form open should look like this


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

fam

@Snapey thank the form working now put i have a problem with

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

NOMGUY
NOMGUY
1 month ago (58,750 XP)

What problem are you getting with this? @fam

fam

thanks all... it works nw put it give me this code

{"_token":"ZQLFhvVqpyA69AGzerzrze0wICTcjRWUd5Iq27uU","title":"sas","submit":"Submit"}

InspiredPrynce

@fam you're submitting the submit button as well?

Snapey
Snapey
1 month ago (1,037,395 XP)

What's wrong with it? Looks correct to me based on this form;

{{csrf_field()}}

<input type="text" name="title" placeholder="Enter">
<input type="submit" name="submit">

</form>

Please sign in or create an account to participate in this conversation.