Model Error: must return a relationship instance
There is a method in the model as follows:
public function adjustbills()
{
if($this->user_combined == '1'){
$invoiceNumberArr = ['xxx'];
return Adjustbill::whereIn('invoice_number',$invoiceNumberArr)->where('user_id', $this->user_id);
}else{
return $this->hasMany(Adjustbill::class, 'invoice_number', 'invoice_number')->where('user_id', $this->user_id);
}
}
When the calling method is model -> When adjustbills,
- If it goes to the following judgment, no error will be reported
- If it goes to the above judgment, it will report an error must return a relationship instance, because laravel uses the following hasMany relationship by default, if not, it will report an error.
Solution:
- Find a way to modify the above logic to the following way of relationship
- Called as :model->adjustbills->get()