我想显示所选的行,但是当我单击名称文档显示最后一行时,编辑按钮也不会从所选字段中检索数据并且不进行更新
这是我的视图 DocumentSideBar.blade.php
<div class="modal fade" id="editModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modifier la document</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="content">
<form class="forms-sample" action="/update/{{$document->id}}" method="POST" enctype="multipart/form-data">
@csrf
@method('POST')
<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>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">modifier</button>
<button type="button" class="btn btn-light" data-dismiss="modal">Annuler</button>
</div>
</div>
</div>
</div>
我在同一页面中使用 data-target =“#editModal”
调用模态 <a href="/documentSideBar/{{$document->id}}/edit" style="float:right" class="btn btn-primary" data-toggle="modal" data-target="#editModal" style="margin-right: 1em">
<i class="glyphicon glyphicon-edit"></i>
</a>
这是Controller中的编辑和更新方法: DocumentsController.php
public function edit($id)
{
$document = Document::findOrFail($id);
return view('documents.edit', compact('document'));
}
public function update($id)
{
$document = Document::findOrFail($id);
$document->nomDocument = request('nomDocument');
$document->description = request('description');
$d = request('path');
//louken ma5taresh document o5ra ye5dh lpath le9dim
if (substr($d, -9) == "undefined") {
$document->path = $document->path;
} else if (isset($d)) {
$document->path = $document->nomDocument . request('path'); // nomdocument.extension
$file = Input::file('file'); // y3awed ysajlo
Storage::putFileAs('usernamee', $file, $document->path);
$document->path = 'usernamee' . '/' . $document->nomDocument . request('path'); // yzidlo l username lel path
}
$document->save();
return redirect('/documentSideBar');
}
在 web.php 中,我调用了修改并显示了ID,但仍显示了最后一个输入行
Route::resource('documentSideBar','DocumentsController');
Route::get('download/{id}','DocumentsController@download');
Route::get('show/{id}','DocumentsController@show');
Route::post('/update/{id}','DocumentsController@update');
我不知道问题出在哪里,我认为是缺少javascript代码,但我不知道如何添加它。这是下图,当我单击“关联”时显示“ fichier文本”