Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel $loop->;偶数或$loop->;奇数不';行不通_Laravel - Fatal编程技术网

Laravel $loop->;偶数或$loop->;奇数不';行不通

Laravel $loop->;偶数或$loop->;奇数不';行不通,laravel,Laravel,所以,我有一个时间轴部分,第一行有不同的html结构,另一行有左侧和右侧视图。奇数边在左边,右边在右边。但是,当我首先使用$loop->时,根本没有错误。但当我使用$loop->偶数或$loop->奇数时,会显示如下错误: 未定义的属性:stdClass::$偶数 或 未定义的属性:stdClass::$odd 这是刀片视图: @if($loop->first)

所以,我有一个时间轴部分,第一行有不同的html结构,另一行有左侧和右侧视图。奇数边在左边,右边在右边。但是,当我首先使用$loop->时,根本没有错误。但当我使用$loop->偶数或$loop->奇数时,会显示如下错误:

未定义的属性:stdClass::$偶数 或 未定义的属性:stdClass::$odd

这是刀片视图:

                                @if($loop->first)
                                <div class="row align-items-center how-it-works d-flex">
                                  <div class="col-2 text-center bottom d-inline-flex justify-content-center align-items-center">
                                    <div class="circle font-weight-bold">{!! $tl->id !!}</div>
                                  </div>
                                  <div class="col-6">
                                    <h5>{!! $tl->company !!}</h5>
                                    <p>{!! $tl->description !!}</p>
                                  </div>
                                </div>
                                <!--path between 1-2-->
                                <div class="row timeline">
                                  <div class="col-2">
                                    <div class="corner top-right"></div>
                                  </div>
                                  <div class="col-8">
                                    <hr/>
                                  </div>
                                  <div class="col-2">
                                    <div class="corner left-bottom"></div>
                                  </div>
                                </div>
                                @elseif($loop->even)
                                <!--second section-->
                                <div class="row align-items-center justify-content-end how-it-works d-flex">
                                  <div class="col-6 text-right">
                                    <h5>{!! $tl->company !!}</h5>
                                    <p>{!! $tl->description !!}</p>
                                  </div>
                                  <div class="col-2 text-center full d-inline-flex justify-content-center align-items-center">
                                    <div class="circle font-weight-bold">{!! $tl->id !!}</div>
                                  </div>
                                </div>
                                <!--path between 2-3-->
                                <div class="row timeline">
                                  <div class="col-2">
                                    <div class="corner right-bottom"></div>
                                  </div>
                                  <div class="col-8">
                                    <hr/>
                                  </div>
                                  <div class="col-2">
                                    <div class="corner top-left"></div>
                                  </div>
                                </div>
                                @elseif($loop->iteration % 2 != 0)
                                <div class="row align-items-center how-it-works d-flex">
                                    <div class="col-2 text-center bottoms d-inline-flex justify-content-center align-items-center">
                                      <div class="circle font-weight-bold">{!! $tl->id !!}</div>
                                    </div>
                                    <div class="col-6">
                                      <h5>{!! $tl->company !!}</h5>
                                      <p>{!! $tl->description !!}</p>
                                    </div>
                                  </div>
                                  <!--path between 1-2-->
                                  <div class="row timeline">
                                    <div class="col-2">
                                      <div class="corner top-right"></div>
                                    </div>
                                    <div class="col-8">
                                      <hr/>
                                    </div>
                                    <div class="col-2">
                                      <div class="corner left-bottom"></div>
                                    </div>
                                  </div>
                                @elseif($loop->last)
                                <div class="row align-items-center how-it-works d-flex">
                                    <div class="col-2 text-center top d-inline-flex justify-content-center align-items-center">
                                      <div class="circle font-weight-bold">{!! $tl->id !!}</div>
                                    </div>
                                    <div class="col-6">
                                      <h5>{!! $tl->company !!}</h5>
                                      <p>{!! $tl->description !!}</p>
                                    </div>
                                  </div>
                                @endif
                                @endforeach

我可以使用$loop->iteration,但是如果我使用它,最后一行似乎会有问题,因为当我使用它时,$loop->last中的脚本不会出现。有人能告诉我如何解决这个问题吗?

奇偶属性仅在laravel 5.8中提供:


也许升级会有所帮助。

奇偶属性仅在laravel 5.8中提供:


也许升级会有所帮助。

您使用的是什么版本的Laravel?它是Laravel 5.7您使用的是什么版本的Laravel?它是Laravel 5.7
public function index()
    {
      $desc = Home::first();
      $users = User::first();
      $site = Site::first();
      $timeline = Timeline::get();
      $services = Services::get();
      $port = Portfolio::get();
      $cat = DB::Table("cat_port")->get();
      $news = DB::table('news')->join('category', 'category.name', '=', 'news.category')->selectRaw('news.*, category.*, category.url as curl, news.created_at as created')->orderBy('created', 'DESC')->get()->take(3);
        return view('home', ['desc' => $desc, 'timeline' => $timeline, 'users' => $users, 'services' => $services, 'port' => $port, 'cat' => $cat, 'news' => $news, 'site' => $site, 'isHome' => true]);
    }