Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

towhid's avatar

Cannot Update my data from my edit from

This is my edit form

<form class="col-md-6" method="PUT" action="/posts">
          <div class="form-group">
            <label for="title">Title</label>
            <input type="text" class="form-control" id="title" name="title" value="{{$post->title}}">
          </div>
          <div class="form-group">
            <label for="body">Body</label>
            <textarea class="form-control" rows="5" name="body">{{$post->body}}</textarea>
          </div>
          
          <button type="submit" class="btn btn-success">Update</button>
        </form>

This is my edit and update controller code

   public function edit($id)
    {
        $post=Post::find($id);
        return view('post.edit',compact('post'));
    }

    public function update(Request $request, $id)
    {
        $post=Post::find($id);
        $post->title = $request->input('title');
        $post->body = $request->input('body');
        $post->save();
        return redirect('/posts')->with('success','Post Updated');
    }

this is my model code

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    //
}

this is my route code


Route::resource('posts','postController');

but not work -- please -- tell me- the - probelm

0 likes
38 replies
jlrdw's avatar

Put in the columns that's editable in model.

towhid's avatar

HEllo @bashy Not work -- this error show

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

No message

bashy's avatar

@jlrdw He's not mass assigning, so that shouldn't be an issue?

@towhid Need more info really. A network request of this would be handy to see what you're sending to what URI.

1 like
Cronix's avatar

@jlrdw that does not apply here, especially due to the way he's saving.

@towhid the Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException is always due to sending the wrong type of request to an endpoint (route). Like you are sending a PUT request to a Route::get(), or something.

Since you're using PUT, you need a

Route::put('/posts', 'YourController@update');
towhid's avatar

@jlrdw use your suggesion like ,

    protected $fillable = [
        'title', 'body'
    ];

but not work still same error

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message

rin4ik's avatar

try this

<form class="col-md-6" method="POST" action="{{route('posts.update',$post->id)}}">
    @method('PUT')
towhid's avatar

@Cronix this is my route link

Route::resource('posts','postController');
Cronix's avatar

Also, you need to add the id of the post you're editing in the form action.

<form class="col-md-6" method="post" action="/posts/{{ $post->id }}">

which is why it's going to the wrong endpoint. You probably don't need that route I suggested earlier since it should be covered by the Route::resource() route, but you do need the id of the post that's getting updated.

See the chart here on how resource controllers are layed out, the http verbs associated with the actions, and the parameters that each requires: https://laravel.com/docs/5.6/controllers#resource-controllers

1 like
towhid's avatar

@rin4ik shoe this error when iam trying to click edit button

ErrorException (E_ERROR)
Missing required parameters for [Route: posts.update] [URI: posts/{post}]. (View: C:\project\temp\resources\views\post\edit.blade.php)
jlrdw's avatar

Clear browser cache and temp view files in between each changing code.

rin4ik's avatar

@towhid I updated reply

<form class="col-md-6" method="POST" action="{{route('posts.update',$post->id)}}">
    @method('PUT')
towhid's avatar

@rin4ik this is message show

@method('PUT')
The page has expired due to inactivity. 

Please refresh and try again.
Vilfago's avatar

parameters should be in an array.

from rin4ik :

<form class="col-md-6" method="POST" action="{{route('posts.update',['post' =>$post->id])}}">
    @method('PUT')
rin4ik's avatar
rin4ik
Best Answer
Level 50

@towhid

<form class="col-md-6" method="POST" action="{{route('posts.update',$post->id)}}">
    @method('PUT')
@csrf
Cronix's avatar

Or just do it like I showed on the previous page many posts ago lol

<form class="col-md-6" method="post" action="/posts/{{ $post->id }}">

they piled on their answers after I posted that, and edited their answers to reflect adding the ID. Looking at you, @rin4ik lol

rin4ik's avatar

@Cronix I didn't see your reply about post id at all. please respect others . don't worry I don't need best reply award. I changed my reply after this error

ErrorException (E_ERROR)
Missing required parameters for [Route: posts.update] [URI: posts/{post}]. (View: C:\project\temp\resources\views\post\edit.blade.php)

@Cronix you are like little child

towhid's avatar

@Vilfago same eorror

The page has expired due to inactivity.

Please refresh and try again.

rin4ik's avatar

@towhid add crsf field


<form class="col-md-6" method="POST" action="{{route('posts.update',$post->id)}}">
    @method('PUT')
@csrf
1 like
bashy's avatar

This escalated quickly :P

I love just passing the model to routes

{{ route('posts.update', $post) }}
1 like
rin4ik's avatar

@bashy yes I like it too , but in controller he expects id :(

   public function update(Request $request, $id)
Snapey's avatar

hang on you lot, I've not proposed a different way yet...

1 like
bashy's avatar

@rin4ik Doesn't matter what you call the variable in the method.

@Snapey Get in there quick!

1 like
Vilfago's avatar

@rin4ik Noted, and no problem for the way you tell me that.

But it's how I always passed argument to route, and it works for me.

I take that from the documentation

Route::get('user/{id}/profile', function ($id) {
    //
})->name('profile');

$url = route('profile', ['id' => 1]);

https://laravel.com/docs/5.6/routing#named-routes

But maybe, only for named routes ?

rin4ik's avatar

@Vilfago your variant also correct. when we need to pass two variables we have to use like u use.

Next

Please or to participate in this conversation.