Javascript 拉雷维尔饼干的奇怪问题

Javascript 拉雷维尔饼干的奇怪问题,javascript,cookies,laravel-4,Javascript,Cookies,Laravel 4,我试图在存在cookie时隐藏一条警告消息 所以我有这个代码: @foreach($alerts as $alert) @if(empty(Cookie::get('alert_'.$alert->id))) <!-- alert --> <div class="alert alert-{{ $alert->type }} text-center"> <a href="#" onclick="createCookie('ale

我试图在存在cookie时隐藏一条警告消息

所以我有这个代码:

@foreach($alerts as $alert)
  @if(empty(Cookie::get('alert_'.$alert->id)))
    <!-- alert -->
    <div class="alert alert-{{ $alert->type }} text-center">
    <a href="#" onclick="createCookie('alert_{{ $alert->id }}','true','9999')" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    {{ $alert->message }}
    </div>
  @endif
@endforeach

我做错了什么?

检查cookie是否存在

试试这个:

您还可以使用请求

要检索cookie的值,请使用以下语法:

$value = $request->cookie('nameOfCookie');
如果需要,添加实例照亮\Http\Request

您可以检查cookie是否存在,如下所示

if (Request::hasCookie('alert_'.$alert->id)) 
{
    // Success code here
} else { 
    // Failure code here
}
您也可以同样检查:

if(Cookie::get('alert_'.$alert->id) != null) { .. }
有用的文档:方法


希望这有帮助。

检查cookie是否存在

试试这个:

您还可以使用请求

要检索cookie的值,请使用以下语法:

$value = $request->cookie('nameOfCookie');
如果需要,添加实例照亮\Http\Request

您可以检查cookie是否存在,如下所示

if (Request::hasCookie('alert_'.$alert->id)) 
{
    // Success code here
} else { 
    // Failure code here
}
您也可以同样检查:

if(Cookie::get('alert_'.$alert->id) != null) { .. }
有用的文档:方法


希望这有帮助。

我都试过了。。。什么都不管用。提醒一下,在此之前我有一个foreach循环,也许这样做了?我发现了问题,但我无法修复它。所以我说,当cookie
alert\uid]
存在时,它需要隐藏,但当它不存在时,它需要显示警报。问题是,他显示了所有警报。现在我需要解决这个问题,但我不知道如何解决。您是否尝试过以下方法:if(!isset(Cookie::get('alert.'$alert->id)){//show}else{//hide}是的,正如我在问题中所说的,isses会阻止我的连接。您能够看到foreach循环中的每个Cookie值吗?有空值吗?试试strlen==0检查???我都试过了。。。什么都不管用。提醒一下,在此之前我有一个foreach循环,也许这样做了?我发现了问题,但我无法修复它。所以我说,当cookie
alert\uid]
存在时,它需要隐藏,但当它不存在时,它需要显示警报。问题是,他显示了所有警报。现在我需要解决这个问题,但我不知道如何解决。您是否尝试过以下方法:if(!isset(Cookie::get('alert.'$alert->id)){//show}else{//hide}是的,正如我在问题中所说的,isses会阻止我的连接。您能够看到foreach循环中的每个Cookie值吗?有空值吗?尝试strlen==0检查???