我一直在搜索谷歌试图找出解决方案。我得到了:
.updatepager(false, true)
当我尝试访问我的帖子索引页面时出现错误,并且无法确定它来自哪里。当我从创建帖子重定向时,我可以访问该页面,但之后我收到错误。据说它应该来自不回归关系,但这是我的关系和代码:
发布
ErrorException in Model.php line 2755: Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
用户
public function category()
{
return $this->belongsTo('App\Category', 'category_id');
}
public function user()
{
return $this->belongsTo('App\User', 'user_id');
}
作用
public function roles()
{
return $this->belongsToMany('App\Role')->withTimestamps();
}
public function posts()
{
return $this->hasMany('App\Post', 'user_id');
}
分类
public function users()
{
return $this->belongsToMany('App\User');
}
index.blade.php
public function posts()
{
return $this->hasMany('App\Post', 'category_id');
}

和post.blade.php
@extends('app')
@section('content')
<h1>Posts</h1>
@if (Auth::check())
@if (Auth::user()->isAdmin())
<a href="/post/create">Create a Post</a>
@endif
@endif
@foreach ($posts as $post)
@include('includes.post', ['post' => $post, 'link' => true])
@endforeach
@stop
&#13;
答案 0 :(得分:1)
在post.blade中打开表单之前,最后一项检查是:
Auth::user()->isAdmin
在另一个文件中,您检查:
Auth::user()->isAdmin() //note the ()
将它们添加到缺少的地方