我想将$category发送给控制器,但是当我在控制器中增强$category时,我发现它是空的。
我在edit.blade.php中的表格
<form action="{{ route('categoryUpdate', $category) }}" method="post" class="ui form">
@method('put')
@csrf
<div class="field">
<label for="title">title</label>
<input type="text" name="title" value="{{$category->title}}" />
</div>
<div class="field">
<label for="description">description</label>
<textarea name="description">{{$category->description}}</textarea>
</div>
<div class="field">
<label for="active">status</label>
<select name="active">
<option value="0" @if($category->active==0) selected @endif>Not Active</option>
<option value="1" @if($category->active==1) selected @endif> Active</option>
</select>
</div>
<div class="field">
<button type="submit" class="ui primary button"> edit</button>
</div>
</form>我的web.php
Route::get('/category/{category}',[CategoryController::class,'show'])->name('categoryShow');
Route::get('/category/edit/{category}',[CategoryController::class,'edit'])->name('categoryEdit');我的控制器
public function update(UpdateCategoryRequest $request, Category $category)
{
dd($category);
}发布于 2022-07-23 21:39:41
为了获得更新,您需要执行以下操作:表单中的更改:
<form action="{{ route('categoryUpdate', $category) }}" method="post" class="ui form">
@csrf
<div class="field">
<label for="title">title</label>
<input type="text" name="title" value="{{$category->title}}" />
</div>
<div class="field">
<label for="description">description</label>
<textarea name="description">{{$category->description}}</textarea>
</div>
<div class="field">
<label for="active">status</label>
<select name="active">
<option value="0" @if($category->active==0) selected @endif>Not Active</option>
<option value="1" @if($category->active==1) selected @endif> Active</option>
</select>
</div>
<div class="field">
<button type="submit" class="ui primary button"> edit</button>
</div>
</form>路线:
Route::post('/category/{category}',[CategoryController::class,'store'])->name('categoryStore');
Route::post('/category/edit/{category}',[CategoryController::class,'update'])->name('categoryUpdate');当我们处理API时,我们使用PUT更新实体,但是当您处理web表单时,使用了POST方法,这是更新实体的最流行方法。
https://stackoverflow.com/questions/73093846
复制相似问题