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()
Read More:
- [Solved] Type error: Argument 1 passed to Monolog\Utils::getClass() must be an instance of Monolog\object
- [Solved] Laravel Upload Files Verificate Error: The file failed to upload.
- Undefined index: name error in composer [How to Solve]
- Laravel-admin php artisan admin:install error reporting problem solution
- Laravel5.5 Error: SQLSTATE[42000] Syntax error or access violation 1071 Specified key was too long; max k
- [Solved] Laravel admin Error: Symfony\Component\Debug\Exception\FatalThrowableError : Class ‘Doctrine\DBAL\Driver\PDOMySql\Driver’ not found
- [Solved] PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;
- PHP parse error: syntax error, unexpected ‘use’
- PHP use __Sleep() and __wakeup() method serializes the object
- [PHP] __autoload function will be called when class_exists does not exist
- [Solved] Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path:
- Using $this when not in object context in (How to Fix)
- TP5 fuzzy Chinese characters error [How to Solve]
- PHP file download, download failed, nginx open() nginx / fastcgi_ temp/2/10/0000000102“ failed (13: Permission denied)
- [Solved] PHP Fatal error: Uncaught Error: Class ‘Redis‘ not found in
- [PHP] Solve Call-time pass-by-reference has been removed
- PHP Error Object of class mysqli could not be converted to string in
- Unserialize(): cause analysis and solution of error at offset
- Error while injecting dependencies into App\Controller\IndexController: No entry or class found for
- PHP large file upload error 413: request entity too large [How to Solve]