Php 为什么拉威尔不承认一段关系?调用未定义的方法Illumb\Database\Query\Builder::model()
这是其中的一个,我什么也没改变,它停止了工作。一个月前,我在服务器上部署的项目版本运行良好,今天我推动了一些与模型关系无关的更改,它突然向我抛出了这个错误Php 为什么拉威尔不承认一段关系?调用未定义的方法Illumb\Database\Query\Builder::model(),php,laravel,relationship,Php,Laravel,Relationship,这是其中的一个,我什么也没改变,它停止了工作。一个月前,我在服务器上部署的项目版本运行良好,今天我推动了一些与模型关系无关的更改,它突然向我抛出了这个错误 Call to undefined method Illuminate\Database\Query\Builder::websites() 引发此错误的脚本的一部分 if(!empty($websites)) { $filePdf->websites()->attach($websites);
Call to undefined method Illuminate\Database\Query\Builder::websites()
引发此错误的脚本的一部分
if(!empty($websites))
{
$filePdf->websites()->attach($websites);
}
$filePdf是App\File类型,我已经用get\u类检查过了
以下是定义的关系
App\File.php
public function websites()
{
return $this->belongsToMany('App\website', 'file_websites', 'file_id', 'website_id');
}
App\website.php
public function files()
{
return $this->belongsToMany('App\File', 'file_websites', 'website_id', 'file_id');
}
文件的表结构
Schema::create('file_websites', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('file_id');
$table->unsignedBigInteger('website_id');
$table->foreign('file_id')->references('id')->on('files');
$table->foreign('website_id')->references('id')->on('websites');
$table->timestamps();
});
在我的本地机器上,它工作正常,没有错误,但一旦我部署它,这种情况就开始发生。任何帮助都将不胜感激
编辑:
下面是$filePdf的声明方式
$filePdf= new File();
$filePdf->filename = $name;
$filePdf->language_id = $request->input('fileLanguage');
$filePdf->save();
尝试将“应用程序\网站”更改为“应用程序\网站”
public function websites()
{
return $this->belongsToMany('App\Website', 'file_websites', 'file_id', 'website_id');
}
什么是$filePdf,向我们展示更多标题中的错误消息与您文章中的错误消息不同。您实际使用的是File.php模型吗?即使用文件::。。。开始您的查询。或者您正在使用DB::table'files'?@timleis是的,我是$filePdf=new File$filePdf->filename=$name$filePdf->language_id=$request->输入'fileLanguage'$filePdf->save@Jeto我将我的问题概括为有类似问题的人。网站是我的问题,但我通常会在googleNope上搜索模型,我的网站文件实际上是较低的w-website.phpyou网站类也较低?是的,类网站扩展了模型{//公共功能文件{return$this->belongsToMany'App\file',file\u websites',website\id',file\u id';}公共函数标记{return$this->belongsToMany'App\Tag',tags\u websites',website\u id',Tag\u id';}}