Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.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
Laravel 尝试列出条目时出现获取未定义属性错误_Laravel_Eloquent - Fatal编程技术网

Laravel 尝试列出条目时出现获取未定义属性错误

Laravel 尝试列出条目时出现获取未定义属性错误,laravel,eloquent,Laravel,Eloquent,我试图列出一些条目标题,但出现了这个未定义的属性错误。我用的是拉威尔7 这是我的模型: class DocumentationItem extends Model { public function docs() { return $this->belongsTo(Documentation::class, 'doc_id'); } } 这是我的控制器: $documentation = DB::table('documentations')-&

我试图列出一些条目标题,但出现了这个未定义的属性错误。我用的是拉威尔7

这是我的模型:

class DocumentationItem extends Model
{

    public function docs()
    {
        return $this->belongsTo(Documentation::class, 'doc_id');
    }
}
这是我的控制器:

$documentation = DB::table('documentations')->where('slug', $docSlug)->first();

$entries = DB::table('documentation_items')->where('doc_id', $documentation->id)->orderBy('id', 'DESC');

return view('frontend.docs.documentation', compact('documentation', 'entries'));
这是我试图在刀片文件中使用的代码:

@foreach($entries as $entry)
    <li>
       <a href="#">{{ $entry->entry_title }}</a>
    </li>
@endforeach
@foreach($entries作为$entry)
  • @endforeach
    完整错误:

    未定义的属性:illumb\Database\MySqlConnection::$entry\u title (观点: F:\xampp\htdocs\test\resources\views\frontend\docs\partials\doc sidebar.blade.php)

    我做错了什么?
    感谢使用DB facade提供的Table方法从表中检索所有行以开始查询。table方法返回给定表的fluent query builder实例,允许您将更多约束链接到查询上,然后使用
    get
    方法最终检索查询结果:

    试试这个

    $entries = DB::table('documentation_items')->where('doc_id', $documentation->id)->orderBy('id', 'DESC')->get();
    

    发布完整错误编辑包含您缺少的错误的帖子以执行查询。在
    $entries=DB::table('documentation\u items')->where('doc\u id',$documentation->id)->orderBy('id','DESC')->get()之后添加一个
    ->get()
    尝试以下操作:
    $entries=DB::table('documentation\u items')->where('doc\u id',$documentation->id)->orderBy('id','DESC')->get()啊。。。。谢谢我错过了。