【问题标题】:Laravel error paginating the data ( render method doesn't exist )Laravel 错误分页数据(渲染方法不存在)
【发布时间】:2021-12-08 15:57:21
【问题描述】:

我正在做一个项目,我有文章表,我获取数据并将其显示在索引页面中

功能

public function index()
{
    $articles = Article::paginate(10);

    return view('dashboard/news/index', compact('articles'));
}

视图

@foreach ($articles as $article)
    <div class="row py-4">
        <div class="col-md-5 article-img">
            <img src="{{ asset('uploads/news-images') }}/{{ $article->img }}" class="w-100">
        </div>
        <div class="col-md-7 p-3 row flex-column justify-content-center">
            <h5 class="text-mine-blue">{{ $article->title }}</h5>
            <span class="text-muted my-2">{{ $article->created_at }}</span>
            <p>{!! \Illuminate\Support\Str::limit($article->content, 170, $end = '...') !!}</p>
            <div class="read-more-btn">
                <a href="{{ route('articles.show', $article->id) }}" class="btn text-light">
                    {{ __('اقرأ المزيد') }}
                </a>
            </div>
        </div>
    </div>
@endforeach
{!! $articles->render() !!}

AppServiceProvider

use Illuminate\Pagination\Paginator;

public function boot()
{
    Paginator::useBootstrap();
}

错误

Method Illuminate\Database\Eloquent\Collection::render does not exist. (View: C:\xampp\htdocs\aqaraty\resources\views\articles\index.blade.php)

【问题讨论】:

    标签: laravel pagination


    【解决方案1】:

    首先,总共有多少篇文章?如果总计数小于您的分页计数,则渲染函数将不会做任何事情。 另外,您可以使用 {!! $articles->render() !!}

    对不起,我是用手机写的。我稍后会编辑我的答案。

    【讨论】:

    • 我编辑了它,但我遇到了同样的错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2018-06-17
    相关资源
    最近更新 更多