【问题标题】:Laravel Routes onclick window.location doesn't workLaravel Routes onclick window.location 不起作用
【发布时间】:2018-04-03 10:46:15
【问题描述】:

为什么这不起作用?

<div class="bewinkel-img"
                 @if(!empty($content->category_id) && isset($website_category->category->group_url))
                    onclick='window.location = "{{URL::route(\"productv2.category\", $website_category->category->group_url.'/'.$website_category->category->complete_url) }}"'>

                 @elseif(!empty($content->category_group_id) && isset($website_category_group->url))
                    onclick='window.location = "{{URL::route("productv2.category", $website_category_group->url) }}"

                 @endif
                <div style="@if($content->height != "") width:100%; height:{{$content->height}}px; @else height:300px; @endif background-image: url('{!!cdn_asset($content->img)!!}')">
                </div>
            </div>

错误信息如下:

Method Illuminate\View\View::__toString() 不能抛出异常,捕获 ErrorException: Parse error: syntax error, unexpected '"', expecting identifier (T_STRING)

感谢任何帮助!

【问题讨论】:

    标签: laravel


    【解决方案1】:

    你有一个错字。改变这一行

    onclick='window.location = "{{URL::route(\"productv2.category\", $website_category->category->group_url.'/'.$website_category->category->complete_url) }}"'>
    

    onclick='window.location = "{{URL::route("productv2.category", $website_category->category->group_url.'/'.$website_category->category->complete_url) }}"'>
    

    【讨论】:

      【解决方案2】:
      onclick='window.location = "{{route('productv2.category', $website_category->category->group_url.'/'.$website_category->category->complete_url) }}"'>
      

      希望这会奏效

      【讨论】:

        【解决方案3】:

        按如下方式修复您的代码:

        <div class="bewinkel-img"
                 @if(!empty($content->category_id) && isset($website_category->category->group_url))
                    onclick='window.location = "{{ route("productv2.category", $website_category->category->group_url . '/' . $website_category->category->complete_url) }}"'>
                @elseif(!empty($content->category_group_id) && isset($website_category_group->url))
                    onclick='window.location = "{{ route("productv2.category", $website_category_group->url) }}"
                @endif
                <div
                    style="
                        @if($content->height != "")
                            width:100%;
                            height:{{$content->height}}px;
                        @else
                            height:300px;
                        @endif
                            background-image: url('{!! cdn_asset($content->img) !!}')
                        "
                ></div>
            </div>
        

        【讨论】:

          【解决方案4】:

          从网址中删除引号。

          所以,改变

          <div class="bewinkel-img"
                           @if(!empty($content->category_id) && isset($website_category->category->group_url))
                              onclick='window.location = "{{URL::route(\"productv2.category\", $website_category->category->group_url.'/'.$website_category->category->complete_url) }}"'>
          

          <div class="bewinkel-img"
                           @if(!empty($content->category_id) && isset($website_category->category->group_url))
                              onclick='window.location = "{{URL::route("productv2.category", $website_category->category->group_url.'/'.$website_category->category->complete_url) }}"'>
          

          【讨论】:

            猜你喜欢
            • 2014-12-12
            • 2019-02-03
            • 2016-12-16
            • 2017-09-20
            • 2015-04-14
            • 2012-02-07
            • 1970-01-01
            • 1970-01-01
            • 2014-09-07
            相关资源
            最近更新 更多