DB可以查询数据库,ORM不能查询
模型Student在app下,代码如下
namespace APP;
use Illuminate\Database\Eloquent\Model;
class Student extends Model{
protected $table = 'student';
protected $primaryKey = "id";
public $timestamps = true;
protected function getDateFormat(){
return time();
}
protected function asDateTime($val){
return $val;
}
}
控制器StudentController代码如下
namespace APP\Http\Controllers;
use APP\Student;
use Illuminate\Routing\Controller;
class StudentController extends Controller{
public function index(){
$students = Student::all();
return view('student.index', [
'students' => $students,
]);
}
public function create(){
return view("student.create");
}
}
显示错误
FatalErrorException in StudentController.php line 16:
Class 'APP\Student' not found
in StudentController.php line 16
at FatalErrorException->__construct() in HandleExceptions.php line 133
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 118
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at StudentController->index() in Controller.php line 78
at call_user_func_array:{E:\Vertrigo\www\my_laravel\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:78}() in Controller.php line 78
at Controller->callAction() in ControllerDispatcher.php line 146
at ControllerDispatcher->call() in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing{closure}() in Pipeline.php line 52
at call_user_func:{E:\Vertrigo\www\my_laravel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:52}() in Pipeline.php line 52
at Pipeline->Illuminate\Routing{closure}() in Pipeline.php line 103
at call_user_func:{E:\Vertrigo\www\my_laravel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:103}() in Pipeline.php line 103
at Pipeline->then() in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack() in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch() in Route.php line 174
at Route->runController() in Route.php line 140
namespace APP;
use Illuminate\Database\Eloquent\Model;
class Student extends Model{
protected $table = 'student';
protected $primaryKey = "id";
public $timestamps = true;
protected function getDateFormat(){
return time();
}
protected function asDateTime($val){
return $val;
}
}
控制器StudentController代码如下
namespace APP\Http\Controllers;
use APP\Student;
use Illuminate\Routing\Controller;
class StudentController extends Controller{
public function index(){
$students = Student::all();
return view('student.index', [
'students' => $students,
]);
}
public function create(){
return view("student.create");
}
}
显示错误
FatalErrorException in StudentController.php line 16:
Class 'APP\Student' not found
in StudentController.php line 16
at FatalErrorException->__construct() in HandleExceptions.php line 133
at HandleExceptions->fatalExceptionFromError() in HandleExceptions.php line 118
at HandleExceptions->handleShutdown() in HandleExceptions.php line 0
at StudentController->index() in Controller.php line 78
at call_user_func_array:{E:\Vertrigo\www\my_laravel\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:78}() in Controller.php line 78
at Controller->callAction() in ControllerDispatcher.php line 146
at ControllerDispatcher->call() in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing{closure}() in Pipeline.php line 52
at call_user_func:{E:\Vertrigo\www\my_laravel\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:52}() in Pipeline.php line 52
at Pipeline->Illuminate\Routing{closure}() in Pipeline.php line 103
at call_user_func:{E:\Vertrigo\www\my_laravel\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:103}() in Pipeline.php line 103
at Pipeline->then() in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack() in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch() in Route.php line 174
at Route->runController() in Route.php line 140
0 个回复