class Locksmith extends ApiModel
{
/**
* @var string
*/
protected $table = 'locksmith';
/**
* @var string
*/
protected $primaryKey = 'locksmith_id';
/**
* 表明模型是否应该被打上时间戳
*
* @var bool
*/
public $timestamps = false;
/**
* 关联查找用户档案信息
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function archive()
{
return $this->belongsTo('App\Models\Archive', 'user_id', 'archive_id');
}
/**
* 多对多查找评价标签.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function tags()
{
return $this->belongsToMany('App\Models\EvaluateTag', 'evaluate_tag_master', 'master_id', 'tag_id')->withPivot('count');
}
}
在调用时$tag = Locksmith::find($locksmithId)->tags()->get()->toArray();会报:Call to a member function tags() on null
public function tags()是一个多对多的关联 当关联表evaluate_tag_master有数据时不会报错
这个怎么办啊?
本地服务器上不报错 服务器上要报错 框架都是更新到最新的了环境一样。
这个错误的原因是
Locksmith::find($locksmithId)
没有查询到结果,返回了null造成的。