illuminate/database使用模型 查询报错
Warning: Uncaught ErrorException: Declaration of Illuminate\Database\Eloquent\Builder::delete() should be compatible with Illuminate\Database\Query\Builder::delete($id = NULL) in /www/zxyp-data-export-service/vendor/illuminate/database/Eloquent/Builder.php:1070
Stack trace:
#0 /www/zxyp-data-export-service/vendor/illuminate/database/Eloquent/Builder.php(26): support\App::{closure}(2, 'Declaration of ...', '/www/zxyp-data-...', 1070, Array)
#1 /www/zxyp-data-export-service/vendor/composer/ClassLoader.php(582): include('/www/zxyp-data-...')
#2 /www/zxyp-data-export-service/vendor/composer/ClassLoader.php(433): Composer\Autoload\{closure}('/www/zxyp-data-...')
#3 [internal function]: Composer\Autoload\ClassLoader->loadClass('Illuminate\\Data...')
#4 /www/zxyp-data-export-service/vendor/illuminate/database/Eloquent/Model.php(1415): spl_autoload_call('Illuminate\\Data...')
#5 /www/zxyp-data-export-service/vendor/illuminate/database/Eloquent/Model.php(1342): Illuminate\Database\Eloquent\Model->newEloquentBuilder(Object(Illu in /www/zxyp-data-export-service/vendor/illuminate/database/Eloquent/Builder.php on line 1070
Fatal error: Cannot make static method Illuminate\Database\Query\Builder::hasMacro() non static in class Illuminate\Database\Eloquent\Builder in /www/zxyp-data-export-service/vendor/illuminate/database/Eloquent/Builder.php on line 1573
Worker[30166] process terminated with ERROR: E_COMPILE_ERROR "Cannot make static method Illuminate\Database\Query\Builder::hasMacro() non static in class Illuminate\Database\Eloquent\Builder in /www/zxyp-data-export-service/vendor/illuminate/database/Eloquent/Builder.php on line 1573"
id有值吗?
我的业务全是查询,出现这个问题后,查一条数据都报这个错,删除vendor重新安装就好。隔断时间又出现这个问题。小白一个,感谢回复
有可能是你的vendor提交到了git/svn版本库,并且vendor 和你的运行环境的PHP版本不匹配。
例如本地PHP7.2安装的
illuminate/database
,vendor下的文件对应的PHP版本是7.2,这个vendor提交到了版本库。但是真正运行的环境是PHP7.4,vendor下的 illuminate/database 还是7.2用法,到了7.4不兼容,导致报错。所以你再重新composer安装一遍时,会把vendor升级到PHP7.4,使用也就正常了。
至于后面又出问题,有可能是做了什么操作vendor被还原回PHP7.2版本。
解决办法,vendor不提交到版本库
好的谢谢提醒 我先排查下环境