我正在创建一个模型文件并尝试使用此模型获取表数据。
每次出现以下错误时:
“SQLSTATE [42S02]:找不到基表或视图:1146表 'laravel_student.students'不存在(SQL:select * from
students
)“
控制器文件如下所示:
namespace project1\Http\Controllers;
use Illuminate\Http\Request;
use project1\Student;
use project1\Http\Requests;
class StudentController extends Controller
{
public function index()
{
$students = Student::all();
return view('student_form',compact('students'));
}
}
答案 0 :(得分:2)
打开Student Model
并添加$table
class Student extends Model {
protected $table = 'student';
}
关注Eloquent Defining Models了解详情