我遇到过Laravel关系的问题,当两个模型ids相同,但另一个有前导零,另一个没有。Productname 012345 | Product A
12345 | Product B 如果在同一查询中加载了这些关系,则只返回第一个关系,而不返回另一个关系。数据库列是字符串,在Product模型中,我已经将incrementing设置为false,并将id属性的cast设置为string。L
当我使用带有Laravel Eloquent的ModelName::with('somerelation')->get()时,如果模型没有这种关系,我会得到Call to undefined relationship但是对于多态关系,我得到了所有相关模型的集合,如果没有定义关系,我想使用with('somerelation')和null。有没有办法避免错误并从with()返回null,或者有条件地使用呢?
我的模型中有BelnogstoMany关系,我这样定义它 class MailUsers extends Model public function group ()return $this->belongsToMany('App\Models\Group', 'user_groups','user_id','group_id');
} 在另一个模型中,当我试图检索带有关系的数据时,
public function findByString($string) return User::where('string', $string)->get();它生成正确的SQL语句,我可以在Sequel中运行它,返回正确的结果。但是,在Laravel (4.2)中调用此方法时,结果总是为空:在另一边
$this->user-&g