Lestah
517
22
Laravel

is this the right way of editing a form?

Posted 6 months ago by Lestah
Route::get('posts/{id}/edit', '[email protected]'); 

i added this one on my web.php even-though i have Route:resource

so when i type localhost8000/posts/1/edit

it should give me the edit page with the form with value

here's my controller


public function edit($id)
    {
     
        $posts = Post::find($id);
        
        return view('posts.edit')->withPosts($posts);
    }

here's my view page edit.blade.php


<form action="{{ route('posts/'.$posts->id) }}" method="POST">
        {{ csrf_field() }}
    
      <div class="form-group">
          <label for="exampleInputEmail1">Title</label>
          <input type="hidden" name="_method" value="PUT">
          <input type="hidden" name="_token" value="{{ csrf_token() }}">
          <input type="text" class="form-control" name="title" placeholder="Enter title" value="{{ $posts->title }}">
      </div>
      <div class="form-group">
          <label for="exampleTextarea">Body</label>
          <textarea class="form-control" name="body" rows="3">{{ $posts->body }}</textarea>
        </div>
        <div class="form-group">
          
          <input type="submit" class="btn btn-success btn pull-right" value="update">
        </div>

      </form>

but it give me error when i try to view the edit page localhost/8000/posts/1/edit it says Route [posts/1] not defined.

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