Пожалуйста, помогите мне решить мою проблему в моем файле удаления в моем проекте, я запутался, потому что он всегда возвращает мне нулевое значение
вот мой editfile.blade.php
@include('partials.navbar')
<link rel="stylesheet" type="text/css" href="http://localhost:8000/assets/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="http://localhost:8000/assets/css/search.css">
<!-- Search -->
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="input-group" id="adv-search">
<input type="text" class="form-control" placeholder="Search file" />
<div class="input-group-btn">
<div class="btn-group" role="group">
<div class="dropdown dropdown-lg">
<button type="button" class="set-width btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="caret"></span></button>
<div class="dropdown-menu dropdown-menu-right" role="menu">
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="file">File type</label>
<select class="form-control">
<option value="pf">Public Weather Forecast</option>
<option value="sf">24 Shipping Forecast</option>
<option value="gale">Gale Warning Forecast</option>
<option value="advisory">Weather Advisory</option>
<option value="tca">Tropical Cyclone Advisory</option>
<option value="swb">Severe Weather Bulletin</option>
<option value="iws">International Warning for shipping</option>
<option value="wof">Weather Outlook Forecast</option>
<option value="spf">Special Forecast</option>
<option value="sm">Surface Maps</option>
</select>
</div>
<div class="form-group">
<label for="contain">Date</label>
<input class="form-control" type="date" />
</div>
<div class="form-group">
<label for="contain">Contains the words</label>
<input class="form-control" type="text" />
</div>
<button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
</form>
</div>
</div>
<button type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- datatable-->
<div class="container">
<div class="row">
<div class="col-md-12">
<h4>File Management</h4>
<table id="mytable2" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<thead>
<tr>
<th>File Name</th>
<th>Date Issued</th>
<th>Uploader</th>
<th>Actions</th>
</tr>
</thead>
<tfoot>
<tr>
<th>File Name</th>
<th>Date Issued</th>
<th>Uploader</th>
<th>Actions</th>
</tr>
</tfoot>
<tbody>
<tbody>
@foreach ($files as $files3)
<tr>
<td>{{ $files3->file_name }}</td>
<td>{{ $files3->date }}</td>
<td>{{ $files3->username }}</td>
<td><a href={{URL::to('/fileDetails?id=') . $files3->id}} class="btn btn-primary btn-xs edit-button" data-title="Edit" ><i class="fa fa-pencil"></i></a>
<button data-id="{{ $files3->id }}" class="btn btn-danger btn-xs delete-button" data-title="Delete" data-toggle="modal" data-target="#delete-modal" ><i class="fa fa-trash"></i></button></td>
</tr>
@endforeach
</tbody>
</table>
<div class="clearfix"></div>
</div>
</div>
</div>
</div><div class="modal fade" id="delete-modal" tabindex="-1" role="dialog" aria-labelledby="delete-modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
<h4 class="modal-title custom_align" id="Heading">Delete this file record</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" action="/deletefile" method="post">
<input name="deletefileid" type="hidden" id="deletefileid" value="">
<div class="alert alert-danger"><i class="fa fa-exclamation-triangle"></i> Are you sure you want to delete this Record?</div>
</div>
<div class="modal-footer ">
<button type="submit" class="btn btn-success" ><i class="fa fa-check"></i> Yes</button>
<button type="submit" class="btn btn-default" data-dismiss="modal"><i class="fa fa-times"></i> No</button>
</form>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
</div>
</div>
</div>
@include('partials.footer')
<script type="text/javascript" src="http://localhost:8000/assets/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://localhost:8000/assets/js/datatable2.js"></script>
<script src="http://localhost:8000/assets/js/modernizr-custom.js"></script>
<!-- polyfiller file to detect and load polyfills -->
<script src="http://localhost:8000/assets/js/polyfiller.js"></script>
<script>
webshims.setOptions('waitReady', false);
webshims.setOptions('forms-ext', {types: 'date'});
webshims.polyfill('forms forms-ext');
</script>
<script>
$(function() {
$(".delete-button").click(function(){
var param = $(this).data('id');
$.ajax({
url: "/erasefile/" + param,
success: function(msg){
var info = JSON.parse(msg)[0];
console.log(info);
$('#deletefileid').val(info.id);
},
error:function(){
alert("failure");
}
});
});
});
</script>
вот моя модель file.php
public static function getdeleteFiles($deleteid)
{
$files = Files::find($deleteid);
$files->delete();
}
вот мой контроллер FileController.php
public function eraseFile($id)
{
$files = Files::where('id',$id)
->get();
return json_encode($files);
}
public function deleteFile()
{
dd(Input::all());
$ftype = Input::get('type');
$oldfile = Input::get('oldfile');
$deleteid = Input::get('deleteid');
$delete = Files::getdeleteFiles($deleteid);
//dd($deleteid);
if ($delete == true) {
File::delete(public_path("uploads/{$ftype}/{$oldfile}"));
return Redirect::to('/edit');
} else {
return Redirect::back()->with('message', 'Delete, Failed');
}
}
и вот мой маршрут
Route::get('/erasefile/{id}', 'FileController@eraseFile');
Route::post('/deletefile', array('uses' => 'FileController@deleteFile'));
Пожалуйста, помогите мне решить эту TIA!
input
а также select
элементы в вашей форме не имеют name
атрибут
ваша функция не вернула никакого значения
public static function getdeleteFiles($deleteid)
{
$files = Files::find($deleteid);
$files->delete();
}
может быть должно быть
public static function getdeleteFiles($deleteid)
{
$files = Files::find($deleteid);
return $files->delete();
}
Других решений пока нет …