此mycontroler
public function index(Request $request, Builder $htmlBuilder)
{
if ($request->ajax())
{
$fields = Field::select(['id','id_lapangan','nama_lapangan','harga_sewa','gambar']);
return Datatables::of($fields)
->addColumn('action', function($field){
return view('datatable._action', [
'model' => $field,
'form_url'=>route('fields.destroy', $field->id),
'edit_url'=>route('fields.edit', $field->id),
'confirm_message'=>'yakin mau hapus '.$field->nama_lapangan .'?'
]);
})
->make(true);
}
删除或更新数据时会出现此错误
public function destroy($id) {
$field=Field::find($id);
if($field->gambar){
$old_gambar = $field->gambar;
$filepath = public_path() . DIRECTORY_SEPARATOR . 'img'
. DIRECTORY_SEPARATOR . $field->gambar;
try {
File::delete($filepath);
}catch (FileNotFoundException $e){
//file sudah di hapus/tidak Ada
}
}
$field->delete();
Session::flash("flash_notification",[
"level"=>"success",
"message"=>"Berhasil menghapus lapangan"
]);
return redirect()->route('fields.index');
}
}
这是我的动作片
{!! Form::model($model, ['url'=> $form_url, 'method' => 'delete' ,
'class' => 'form-inline js-confirm','data-confirm'=>$confirm_message]) !!}
<a href="{{ $edit_url}}">Ubah</a> |
{!! Form::submit('Hapus', ['class'=>'btn btn-xs btn-danger']) !!}
{!! Form::close() !!}
当我点击按钮删除和更新时发生此错误, 一段时间它的工作,但删除没有选定ID的数据,