我有一个模特
Education.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Education extends Model
{
public $timestamps = FALSE;
public function Member(){
return $this->belongsTo('App\Member');
}
}
在数据库中我有一个名为 educations 的表在控制器中,当我试图通过 App\Education 模型访问教育表的数据时,我收到此错误
Connection.php第770行中的QueryException:SQLSTATE [42S02]:未找到基表或视图:1146表'dsse.education'不存在(SQL:select * from education)
为什么laravel在数据库中搜索 education 表,它应该搜索 educations 表 . 问题是什么?
这是控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Member as Member;
use App\Education as Education;
class memberController extends Controller
{
public function addMember(){
$education = Education::all();
var_dump($education);
}
}
2 回答
将其添加到您的模型中 . 您可以设置任何自定义表名称,如下所示
I had the same problem before,
是的,它是一个添加的解决方案
但问题是因为laravel使用了一个叫做的类
内
而且这个课不只是在单词或结尾处添加"s" ......它是真正的多元化,教育是一个不可数字,信息也是如此......所以 you need to add $table to your model .