[英]How to delete from the database using JQuery and Laravel
I have the following code with an if statement depending if a user has saved an article or not. 我有以下代码和if语句,具体取决于用户是否保存了文章。 I'm simply trying to delete the article from the database using jquery. 我只是试图使用jquery从数据库中删除文章。 I unsure where im going wrong? 我不确定我哪里出错了? help is much appreciated! 非常感谢您的帮助!
View: 视图:
<form action="{{URL::route('article-delete')}}" method="post" id="article_one_delete">
<div class="form-group">
<input type="hidden" name="first_desc" value="{{$firstrow->description}}" class="form-control">
</div>
<div class="form-group">
<input type="hidden" name="first_title" value="{{$firstrow->title1}}" class="form-control">
</div>
<button type ="button" id="Recodelete" class="btn btn-success btn-xs">UnSave</button>
{{Form::token()}}
</form>
Route: 路线:
Route::delete('/home/', array( 'as' => 'article-delete',
'uses' => 'HomeController@deletearticle'));
Controller: 控制器:
public function deletearticle(){
$firsttitle = Input::get('first_title');
$articledelete = UserSaveArticle::where('user_id', Auth::id()
->where ('user_save_articles.chosen_title', $firsttitle))->delete();
return true;
JQuery: JQuery的:
$(document).ready(function(){
$('#Recodelete').on('click', function(){
var article_one_delete = $('#article_one_delete').serializeArray();
var url_d = $('#article_one_delete').attr('action');
$.get(url_d, article_one_delete, function(data){
console.log(data);
});
});
});
Route::delete('/article/{id}', ['as' => 'article-delete', 'uses' => 'HomeController@deleteArticle']);
HomeController
$id variable (article ID) will be available as a method parameter: 在HomeController
$ id变量(商品ID)将作为方法参数提供: function deleteArticle($id)
{
…
}
$.ajax({
url: '/article/' + articleId,
type: 'DELETE',
success: function(result) {
// Do something with the result
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.