我有一个模型
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 的表 在 Controller 中,当我尝试通过 App\Education 模型访问教育表的数据时,出现此错误
QueryException in Connection.php line 770: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dsse.education' doesn't exist (SQL: select * from
education
)
为什么 Laravel 在数据库中搜索 education 表,而它应该搜索 education 表。有什么问题?
这是 Controller
<?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);
}
}
最佳答案
将此添加到您的模型中。您可以如下设置任何自定义表名
protected $table = 'educations';
关于php - 在 Laravel 5.3 中找不到基表或 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42611890/