当我单击“编辑”按钮时,该编辑不起作用,它会恢复输入的值,但不会在数据库中对其进行修改
Edit.blade.php
@extends('index')
@section('content')
<script language="javascript" type="text/javascript" src={{ URL::to('js/extension.js') }}></script>
<div class="form-group" style="margin-top: 100px;">
<form class="forms-sample" action="/documentSideBar" method="get" enctype="multipart/form-data">
@csrf
@method('PATCH')
<div class="form-group">
<label for="nomDocument">Nom document</label>
<input type="text" class="form-control" id="nomDocument" name="nomDocument"
value="{{$document->nomDocument}}" onChange='getoutput2()'>
</div>
<div class="form-group">
<label for="description">Description</label>
<input type="text" class="form-control" id="description" name="description"
value="{{$document->description}}">
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group row">
<label class="col-sm-3 col-form-label">Type</label>
<div class="col-sm-9">
<select class="form-control">
<option>Documents administratifs</option>
<option>Documents financiéres</option>
</select>
</div>
</div>
</div>
</div>
<div class="form-group">
<label for="fille">Importer un fichier</label>
<input type="file" onChange='getoutput()' name="file" id="fille" class="form-control">
<input id='extension' type='hidden' name='extension'>
<input id="pathe" type="hidden" name="path">
</div>
<button type="submit" class="btn btn-success mr-2">Modifier</button>
<button class="btn btn-light">Annuler</button>
</form>
</div>
@endsection
documentSideBar.blade.php
<td style="width:300px">
<a href="/download/{{$document->id}}" class="btn btn-success"><i
class="glyphicon glyphicon-download-alt"></i></a>
<a href="/documentSideBar/{{$document->id}}/edit" style="float:right" class="btn btn-primary">
<i class="glyphicon glyphicon-edit"></i>
</a>
<form action="{{ action('DocumentsController@destroy', $document->id)}}" method="POST">
@method('DELETE')
@csrf
<button class="btn btn-danger"><i
class="glyphicon glyphicon-trash"></i></button>
</form>
</td>
这是控制器中的编辑和更新方法 DocumentsController.php
public function edit($id)
{
$document = Document::findOrFail($id);
return view('documents.edit', compact('document'));
}
public function update(Document $document)
{
$document->nomDocument = request('nomDocument');
$document->description = request('description');
$d=request('path');
if(isset($d)){
$document->path ='username'.'/'.request('path');
}
$document->save();
return redirect('/documentSideBar');
}
public function show($id)
{
$document = Document::findOrFail($id);
return view('documentSideBar', compact('document'));
}
我也想调整按钮,而不是如何在它们之间留出空间
答案 0 :(得分:2)
错误在于web.php:这是正确的路线
Route::resource('documentSideBar','DocumentsController');
Route::get('download/{id}','DocumentsController@download');
Route::get('show/{id}','DocumentsController@show');
Route::post('/update/{id}','DocumentsController@update');
答案 1 :(得分:0)
您应该将表单方法更改为POST,并将操作更改为资源模式:
<form class="forms-sample" action="{{route('documentSideBar.update', $document->id)}}" method="POST" enctype="multipart/form-data"
@csrf
@method('PATCH')
在修改数据库中的数据时,应使用POST而不是GET。
看看here,以了解有关这些方法的更多信息。
您还应该查看Resource Controller部分,以了解有关您正在使用什么的更多信息