douxing9813
2015-09-02 16:00
浏览 11
已采纳

Laravel 5.1 url值未传递给控制器​​PUT方法

I have a simple form for updating book info.

<form action="{{ action('BookController@update') }}" method="POST" class="form-horizontal">

  <input type="text" id="title" class="form-control" name="title" placeholder="title" value="{{ $book[0]->title }}">

  <input type="text" id="author" class="form-control" name="author" placeholder="author" value="{{ $book[0]->author }}">
      ......................

  <button type="submit" class="btn btn-primary">Save</button>

  <input type="hidden" name="_method" value="PUT">

  <input type="hidden" name="_token" value="{{ csrf_token() }}" />

</form>

Controller:

public function update(Request $request, $id)
{
    $book = new Book;

    $title      = $request->input('title');
    $author     = $request->input('author');
    $category   = $request->input('category');
    $date       = $request->input('date');

    if ($book->updateBook($id, $title, $author, $category, $date)) {
        return redirect('books')->with('status', 'Successfuly edited!');
    }
    else {
        return dd($id);
    }
}

The problem is, it doesn't pass the right $id. It pass a string {books}

Basically $id = "{books}"

It should be an integer (31) from url /books/31/edit

In routes is defined as a resource with all available default methods What can i do?

3条回答 默认 最新

相关推荐 更多相似问题