Laravel 5 如何使用laravel中的数据集合跳转到

Laravel 5 如何使用laravel中的数据集合跳转到,laravel-5,collections,Laravel 5,Collections,我正在我的项目中实现跳转到…功能。我想要的是: 如果用户在第一项中,则左侧按钮不包括在内 如果用户在最后一项中,则不包括右按钮 左侧按钮应具有与当前/所选项目前的链接相同的链接 右按钮应具有与当前/所选项目后面的链接相同的链接 请参阅下面我的代码: 控制器 看法 @foreach($course->topics as$topic) @foreach(collect($topic->assignments)->合并(collect($topic->quizzes))->合并(collect($t

我正在我的项目中实现
跳转到…
功能。我想要的是:

  • 如果用户在第一项中,则左侧按钮不包括在内
  • 如果用户在最后一项中,则不包括右按钮
  • 左侧按钮应具有与当前/所选项目前的链接相同的链接
  • 右按钮应具有与当前/所选项目后面的链接相同的链接
  • 请参阅下面我的代码:

    控制器

    看法

    
    @foreach($course->topics as$topic)
    @foreach(collect($topic->assignments)->合并(collect($topic->quizzes))->合并(collect($topic->add_links))->排序('item_number')作为$first_item)
    @如果($first_item->id!=$assignment->id)
    @恩迪夫
    @endforeach
    @endforeach
    跳到
    
      @foreach($course->topics as$topic)
    • 主题{{$Topic->Topic_number}
    • @foreach(collect($topic->assignments)->合并(collect($topic->quizzes))->合并(collect($topic->add_links))->排序('item_number')作为$topic_item)
    • @如果($topic\u item->item\u type()=='assignment') @elseif($topic\u item->item\u type() @elseif($topic\u item->item\u type()=='add\u link') @恩迪夫
    • @endforeach @endforeach
    示例
    下拉链接

    分配1
    分配2
    Quiz1
    QUiz2
    评论员1

    如果我单击了Assignment2,左边的按钮会有
    id
    链接到
    Assignment1
    。如果我单击Reviewer1,右键消失,左键具有
    id
    或指向Quiz2的链接,与其他链接相同

    $course = Course::with([
      'assignments' => $undeleted,
      'quizzes' => $undeleted,
      'add_links' => $undeleted
    ])->findOrFail($id);
    $course_items = collect($course->assignments);
    $course_items = $course_items->merge(collect($course->quizzes));
    $course_items = $course_items->merge(collect($course->add_links));
    $course_items = $course_items->sortBy('item_number');
    
    <div class="jump-to">
        <div class="pull-right">
            <div class="btn-group" role="group">
    
                @foreach($course->topics as $topic)
                    @foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortBy('item_number') as $first_item)
                        @if($first_item->id != $assignment->id)
                            <a href="#" class="btn btn-primary">
                                <i class="fa fa-angle-left"></i>
                            </a>
                        @endif
                        <?php break 2; ?>
                    @endforeach
                @endforeach
                <div class="btn-group" role="group">
                    <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        Jump to <div class="caret"></div>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        @foreach($course->topics as $topic)
                            <li class="jdivider">
                                Topic {{ $topic->topic_number }}
                            </li>
                            @foreach(collect($topic->assignments)->merge(collect($topic->quizzes))->merge(collect($topic->add_links))->sortBy('item_number') as $topic_item)
                                <li>
                                    @if($topic_item->item_type() == 'assignment')
                                        <a title="Assignment: {{ $topic_item->name }}" class="regular-link" href="{{ route('assignment.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}">
                                            <i class="fa fa-tasks"></i> {{ str_limit($topic_item->name, 15) }}
                                        </a>
                                    @elseif($topic_item->item_type() == 'quiz')
                                        <a title="Quiz: {{ $topic_item->name }}" class="regular-link" href="{{ route('quiz.view', ['course_id' => $course->id, 'id' => $topic_item->id]) }}">
                                            <i class="fa fa-file-text"></i> {{ str_limit($topic_item->name, 15) }}
                                        </a>
                                    @elseif($topic_item->item_type() == 'add_link')
                                        <a href="#">
                                            @if(!empty($topic_item->file_location) && in_array(strtolower(last(explode('.', $topic_item->file_location))), ['pdf', 'docx', 'doc']))
                                                <i class="fa fa-file-pdf-o"></i>
                                            @elseif(empty($topic_item->file_location))
                                                <i class="fa fa-globe"></i>
                                            @else
                                                <i class="fa fa-file-text-o"></i>
                                            @endif
                                            {{ str_limit($topic_item->name, 15) }}
                                        </a>
                                    @endif
                                </li>
                            @endforeach
                        @endforeach
                    </ul>
                </div>
                <a href="#" class="btn btn-primary">
                    <i class="fa fa-angle-right"></i>
                </a>
            </div>
        </div>
    </div>