我有一个应用程序我想要更新数据,但是当我想要更新数据而没有更改时,我在系统中发现错误。但如果我成功更改了其中一个数据。
这是我的控制器:
public function getDetails($id) {
$data['row'] = data_kos::find($id);
return view('details_add',$data);
}
public function postDetailsSave($id) {
$simpan= array();
if (Request::hasfile('photo1')) {
$destinationPath = 'uploads'; // upload path
$extension = Request::file('photo1')->getClientOriginalExtension(); // getting image extension
$fileName = rand(11111,99999).'.'.$extension; // renameing image
Request::file('photo1')->move($destinationPath, $fileName); // uploading file to given path
$simpan['photo1']=$fileName;
}
if (Request::hasfile('photo2')) {
$destinationPath1 = 'uploads'; // upload path
$extension1 = Request::file('photo2')->getClientOriginalExtension(); // getting image extension
$fileName1 = rand(11111,99999).'.'.$extension1; // renameing image
Request::file('photo2')->move($destinationPath1, $fileName1); // uploading file to given path
$simpan['photo2']=$fileName1;
}
if (Request::hasfile('photo3')) {
$destinationPath2 = 'uploads'; // upload path
$extension2 = Request::file('photo3')->getClientOriginalExtension(); // getting image extension
$fileName2 = rand(11111,99999).'.'.$extension2; // renameing image
Request::file('photo3')->move($destinationPath2, $fileName2); // uploading file to given path
$simpan['photo3']=$fileName2;
}
if (Request::hasfile('photo4')) {
$destinationPath3 = 'uploads'; // upload path
$extension3 = Request::file('photo4')->getClientOriginalExtension(); // getting image extension
$fileName3 = rand(11111,99999).'.'.$extension3; // renameing image
Request::file('photo4')->move($destinationPath3, $fileName3); // uploading file to given path
$simpan['photo4']=$fileName3;
}
if (Request::hasfile('photo5')) {
$destinationPath4 = 'uploads'; // upload path
$extension4 = Request::file('photo5')->getClientOriginalExtension(); // getting image extension
$fileName4 = rand(11111,99999).'.'.$extension4; // renameing image
Request::file('photo5')->move($destinationPath4, $fileName4); // uploading file to given path
$simpan['photo5']=$fileName4;
}
DB::table('data_kos')->where('id', $id)->update($simpan);
Session::flash('edit', 'Data successfully edited');
return Redirect::to('home');
}
在这里我的观点:
<form method='post' action='{{action("KostController@postDetailsSave")."/$row->id" }}' enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="box-body">
<div class="box-body">
<div class='form-group col-sm-12'>
<label>Title</label>
<input type='text' class='form-control' name='title' value='{{ @$row->title }}' readonly />
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo1 }}" height="70px">
<input type='file' class='form-control' name='photo1' value='{{ @$row->photo1 }}'/>
</div><br>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo2 }}" height="70px">
<input type='file' class='form-control' name='photo2' value='{{ @$row->photo2 }}'/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo3 }}" height="70px">
<input type='file' class='form-control' name='photo3' value='{{ @$row->photo3 }}'/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo4 }}" height="70px">
<input type='file' class='form-control' name='photo4' value='{{ @$row->photo4 }}'/>
</div>
<div class='form-group col-sm-4'>
<label>gambar</label><br>
<img src="../../uploads/{{ $row->photo5 }}" height="70px">
<input type='file' class='form-control' name='photo5' value='{{ @$row->photo5 }}'/>
</div>
<div class='form-group col-sm-12'>
<button type='submit' class='btn btn-primary'><i class='fa fa-save'></i> Simpan</button>
</div>
</div><!-- /.box -->
</form>
答案 0 :(得分:0)
从错误消息中可以看出,您遇到的问题是$simpan
为空。也许在尝试更新数据库之前dd()该变量的内容,看看是否可能是这种情况......