我试图使用Eloquents find方法从我的数据库中检索一条记录,但是,它意外地返回了null。如果我在数据库上手动运行查询,那么它将返回预期的记录。我在Laravel中使用了以下内容:以及直接在数据库上执行以下操作:
SELECT * FROM support WHERE id =没有报告任何错误(据我所见),如果我将Eloquent method更改为' all‘,那么所有记录都会正确返回</e
当我使用带有Laravel Eloquent的ModelName::with('somerelation')->get()时,如果模型没有这种关系,我会得到Call to undefined relationship但是对于多态关系,我得到了所有相关模型的集合,如果没有定义关系,我想使用with('somerelation')和null。有没有办法避免错误并从with()返回null,或者有条件地使用呢?
嗨,伙计们,我正在使用jessengers mongodb扩展,我已经有了mongodb扩展,问题是它显示了被保护的属性,我的代码是:<?php
use \Jenssegers\Mongodb\Eloquent\SoftDeletes;
{
public $guarded = ['password']
;}public function people() return null; // here I could add checking if there is aModel class and if not return null但是当使用这种方法时,$model = Model::with('people')->get();不起作用。我将有几十个关系,我无法在with中使用它们的列表。最好的方法是使用一些empt