繁体   English   中英

我有一个 if 语句,但我有问题

[英]i have an if statement but i have a problem

所以我有一个问题,很难解释,但可以描述如下:

如果我分页 10,这是输出

上图,我分页10,从下面的代码可以看出:

$list = Anime::where('status', 1)->paginate(10);

输出 2 分页 5

如果上图,我分页5,从下面的代码可以看出:

$list = Anime::where('status', 1)->paginate(5);

显示以下代码图像(刀片文件):

<div class="flex-shrink-0 h-10 w-10">
 @if ($creator[$i]->profile_photo_path)
  @php
  $isi = $creator[$i]->profile_photo_path;
 @endphp
  <img class="h-10 w-10 rounded-full" src='{{ asset("storage/$isi") }}' alt="">
 @elseif ($creator[$i]->profile_photo_path == null || !$creator[$i]->profile_photo_path)
  <img class="h-10 w-10 rounded-full" src="{{ asset('storage/profile-photos/default.svg') }}"     alt="">
 @endif
</div>

以下是刀片文件的完整内容:

        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Public List Anime') }}
        </h2>
    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            
            <div class="flex flex-col">
                <div class="-my-2 overflow-x-hidden sm:-mx-6 lg:-mx-8">
                    <div class="py-2 align-middle inline-block min-w-full sm:px-6 lg:px-8">
                        <div class="shadow overflow-hidden border-b border-gray-200 sm:rounded-lg">
                            <table class="min-w-full divide-y divide-gray-200">
                                <thead class="bg-gray-50">
                                    <tr>
                                        <th scope="col" class="hidden md:inline-block px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                            Username
                                        </th>
                                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                            Title
                                        </th>
                                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                            Genre
                                        </th>
                                        <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
                                            Rating
                                        </th>
                                        <th scope="col" class="relative px-6 py-3">
                                            <span class="sr-only">Edit</span>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody class="bg-white divide-y divide-gray-200">
                                    @foreach ($list as $i => $l)
                                    <tr>
                                        <td class="hidden md:inline-block px-6 py-4 whitespace-nowrap">
                                            <div class="flex items-center">
                                                <div class="flex-shrink-0 h-10 w-10">
                                                    @if ($creator[$i]->profile_photo_path)
                                                    @php
                                                    $isi = $creator[$i]->profile_photo_path;
                                                    @endphp
                                                    <img class="h-10 w-10 rounded-full" src='{{ asset("storage/$isi") }}' alt="">
                                                    @elseif ($creator[$i]->profile_photo_path == null || !$creator[$i]->profile_photo_path)
                                                    <img class="h-10 w-10 rounded-full" src="{{ asset('storage/profile-photos/default.svg') }}" alt="">
                                                    @endif
                                                </div>
                                                <div class="ml-4">
                                                    <div class="text-sm font-medium text-gray-900">
                                                        {{ Illuminate\Support\Str::of($l->email)->title() }}
                                                    </div>
                                                </div>
                                            </div>
                                        </td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <div class="text-sm text-gray-900">{{ Illuminate\Support\Str::of($l->title)->title() }}</div>
                                        </td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
                                                @php $g = explode(',', $l->genre) @endphp
                                                {{ Illuminate\Support\Str::of($g[0])->title() }}
                                            </span>
                                        </td>
                                        <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
                                            
                                            {{ $l->score }} <i class="fal fa-stars"></i>
                                        </td>
                                        <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                                            <a href="{{ route('show', $l->id) }}" class="text-indigo-600 hover:text-indigo-900">Detail</a>
                                        </td>
                                    </tr>

                                    
                                    @endforeach
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <span>
                {{ $list->links() }}
            </span>
        </div>
    </div>

这是controller方法索引:

public function index()
    {
        $list = Anime::where('status', 1)->paginate(5);

        $creator = Anime::join('users', 'users.email', '=', 'animes.email')
        ->where('status', 1)
        ->get('users.profile_photo_path');

        return view('anime.publicList', compact('list', 'creator'));
    }

问题是,如果我将其分页为 5,那么当在第二页上,用户图像变成管理图像(与第一个图像分页 10 不同)

#通过以下方式解决:

我尝试将变量 $creator 更改为分页(等同于 $ 日本动漫变量)

所以我改为如下内容:

$creator = Anime::join('users', 'users.email', '=', 'animes.email')
    ->where('status', 1)
    ->select('users.*')
    ->paginate(5);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM