У меня есть список "идей" в моей базе данных.Каждый раз, когда пользователь нажимает кнопку, отображается новая случайная идея (и добавляется в файл cookie).Если идей не осталось, на кнопке появляется сообщение, чтобы начать все сначала (= удалить cookie и получить случайное представление).
Вышеописанное работает до сих пор.Проблема в том, чтобы начать все сначала (= удалить куки и получить случайную идею снова).
В моем вызове ajax есть:
$.ajax({
type: "POST",
url: "/idea",
data: { noideas: $("#noideas").val() },
success: function(response) {
if(response == false)
{
$(".card").fadeOut(function(){
$(this).remove();
$('<div class="card card-primary">' +
'<div class="card-header">' +
'<h3 class="card-title">Einde</h3>' +
'</div>' +
'<div class="card-body">U heeft alle ideeën bekeken.</div>' +
'</div>').appendTo('.content').fadeIn();
});
$("#noideas").val('true');
$("#idea").text("Start opnieuw.");
}
else
{
$(".card").fadeOut(function(){
$(this).remove();
$('<div class="card card-primary">' +
'<div class="card-header">' +
'<h3 class="card-title">' + response.title + '</h3>' +
'</div>' +
'<div class="card-body">' + response.description +
'</div>' +
'</div>').appendTo('.content').fadeIn();
});
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
});
В поле ввода с идентификатором noideas Я устанавливаю, если не осталось идей.
В моей функции (в контроллере) у меня есть:
public function idea(Request $request)
{
$noideas = $request->input('noideas');
// cookie
$ideas = Cookie::get('ideas');
$ideas = unserialize($ideas);
$random_idea = Idea::whereNotIn('id', $ideas)->inRandomOrder()->first();
if($random_idea)
{
if(!in_array($random_idea->id,$ideas))
{
$ideas[] = $random_idea->id;
}
}
else
{
$random_idea = false;
}
Cookie::queue('ideas', serialize($ideas));
if($noideas == "true")
{
Cookie::queue(
Cookie::forget('ideas')
);
$ideas = array();
$random_idea = Idea::whereNotIn('id', $ideas)->inRandomOrder()->first();
}
return response()->json($random_idea);
}
Проблема в том, что куки не удаляются.Что я делаю не так?