I have a problem with routes in laravel. Do you have any idea? This is my code.
My jquery to send variable:
$('.del').click(function(event){
event.preventDefault();
if (confirm("Are you sure?")) {
var id = $(this).attr('id');
var actor = $('#actor').val();
var url = "{{Asset('lesson/delete-chapter')}}";
var url_dir ="{{Asset('lesson/view')}}"+actor; //this just url to direct after del
$.get(url,{id:id},function(data){
alert(data);
$(location).attr("href",url_dir);
});
}
return false;
});
This is my routes:
Route::get('lesson/delete-chapter','LessonController@postDeleteChapter');
This is my controller:
public function postDeleteChapter(){
$id = Input::get('id');
$less = Lesson::where('chapter_id','=',$id);
if(count($less)>0){
$data['re'] = "Please delete lessons in this chapter!";
}
else{
$chapter = Chapter::find($id);
$less->delete();
$data['re'] = "Deleted!";
}
echo json_decode($data);
}
It's get error with routes delete, I dont know why, can you help me? Thanks you very much.
</div>
Use url
function instead of asset
.
$('.del').click(function(event){
event.preventDefault();
if (confirm("Are you sure?")) {
var id = $(this).attr('id');
var actor = $('#actor').val();
var url = "{{url('lesson/delete-chapter')}}";
var url_dir ="{{url('lesson/view')}}"+actor; //this just url to direct after del
$.get(url,{id:id},function(data){
alert(data);
$(location).attr("href",url_dir);
});
}
return false;
});