edit.blade.php:
{!! Form::model($post, array('method'=>'PATCH','url'=>'/posts/{post}'.$post->id)) !!}
{{ method_field('PATCH') }}
{{csrf_field()}}
<label for="title">Titolo</label>
<input type="text" class="form-control" id="title" name="title" value="{{$post->title}}">
<label for="body">Corpo</label>
<textarea id="body" name="body" class="form-control" value="{{$post->body}}">
</textarea>
路由/ web.php:
Route::get('/', 'PostsController@index')->name('home');
Route::get('/posts/create', 'PostsController@create');
Route::post('/posts', 'PostsController@store');
Route::get('/posts/{post}', 'PostsController@show');
Route::get('/posts/tags/{tag}', 'TagsController@index');
Route::post('/posts/{post}/comments','CommentsController@store');
Route::get('/posts/{id}/edit', 'PostsController@edit');
Route::get('/edit/{post}', 'PostsController@update');
Route::patch('/post/{post}', 'PostsController@update');
Route::get('/register', 'RegistrationController@create');
Route::post('/register', 'RegistrationController@store');
Route::get('/login', 'SessionsController@create');
Route::post('/login', 'SessionsController@store');
Route::get('/logout', 'SessionsController@destroy');
postController:
public function edit( Post $post )
{
return view('posts.edit', compact('post'));
}
public function update(Request $request, Post $post)
{
Post::where('id', $post)->update($request->all());
return redirect('/home');
}
答案 0 :(得分:1)
您在此处使用model binding,因此请将其更改为:
public function update(Request $request, Post $post){
$post->update($request->all());
return redirect('/home');
}
另外,将网址更改为:
'url' => '/posts/' . $post->id
此外,请删除这些字段,因为{!! Form::model() !!}
会自动为您插入这些字段:
{{ method_field('PATCH') }}
{{ csrf_field() }}
答案 1 :(得分:0)
更改:强>
select distinct customerId, (
select StoreCity,
TransactionDate,
TransactionDescription
from Temp
where customerId = T.customerId
for json path) [JSON]
from Temp T
要强>
Post::where('id', $post)->update($request->all());
答案 2 :(得分:0)
新路线:
Route :: patch('/ posts / {id} / edit / {post}','UpdateController @ update');
{!! Form :: model($ post,array('method'=&gt;'POST','url'=&gt;'/ posts / {id} / edit'。$ post-&gt; id))!!}
我认为/ posts / {id} / edit not working