Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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
Php Laravel 5.8中分页中的链接返回错误_Php_Laravel_Laravel 5 - Fatal编程技术网

Php Laravel 5.8中分页中的链接返回错误

Php Laravel 5.8中分页中的链接返回错误,php,laravel,laravel-5,Php,Laravel,Laravel 5,我是拉威尔的初学者。我在我的项目中使用了Laravel5.8 我想用分页显示我的帖子列表 我对分页有问题 我有以下代码: class ForumCategory extends Model { use scopeActiveTrait; protected $quarded = ['id']; protected $fillable = ['company_id', 'enable', 'name', 'url_address', 'enable']; publ

我是拉威尔的初学者。我在我的项目中使用了Laravel5.8

我想用分页显示我的帖子列表

我对分页有问题

我有以下代码:

class ForumCategory extends Model
{
    use scopeActiveTrait;

    protected $quarded = ['id'];
    protected $fillable = ['company_id', 'enable', 'name', 'url_address', 'enable'];
    public $timestamps = false;

    public function themes()
    {
        return $this->hasMany('App\ForumPost', 'id_category', 'id')->where('parent_id', '=', null);
    }

    public function lastPost()
    {
        return $this->themes()->orderBy('id', 'desc')->first();
    }
}

class ForumPost extends Model
{
    use scopeActiveTrait;

    protected $quarded = ['id'];
    protected $fillable = ['company_id', 'id_category', 'parent_id', 'user_id', 'date', 'title', 'content', 'url_address', 'enable'];
    public $timestamps = true;
    protected $table = 'forum';

    public function category()
    {
        return $this->belongsTo('App\ForumCategory', 'id_category');
    }

    public function author()
    {
        return $this->belongsTo('App\User', 'user_id');
    }

    public function postCount()
    {
        return $this->hasMany('App\ForumPost', 'parent_id', 'id')->where('parent_id', '!=', null)->count();
    }
}



@foreach ($forums as $forum)
    Welcome in {{ $forum->name }}<br/>
    @foreach ($forum->themes as $post)
        Post: {{ $post->title }}
        <div class="paginationFormat"></div>
        <div class="text-right">{{ $post->links() }}</div>
    @endforeach
    <div class="paginationFormat"></div>
    <div class="text-right">{{ $forums->links() }}</div>
@endforeach
我需要$post的分页

我的代码中有一个错误:

Call to undefined method App\ForumPost::links() (View: ....)
我怎样才能修理它

我想显示$forum和$post的分页


我该怎么做呢?

首先,您应该使用控制器返回分页数据。但是,如果您想在相同的代码中实现结果,请执行类似的操作

@foreach$forum->themes->paginate10作为$post
您是否已经像在ForumCategory中一样在ForumPost中进行分页?您不能在after事实中改变分页结果,或者将其转换为集合并销毁分页实例。此外,setRelation可能会以不应该的方式被滥用。为什么要在双括号内使用函数?{{$post->links},我假设$post包含成员,使用{{$post->$link}。你可以把一个垃圾$post;在输出之前,向我们展示其中一个的内容。Idem用于->链接。
Call to undefined method App\ForumPost::links() (View: ....)