Cannot Update my data from my edit from

Posted 8 months ago by towhid

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

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.