Php Laravel无法识别模型
我刚开始尝试Laravel,但我遇到了一些问题,尤其是在使用用户模型时。在我尝试使用用户模型访问数据库并在视图中显示条目之前,指南中的所有内容都对我有效。当我试图在浏览器中访问public/users/时,我遇到一个页面,上面写着,哇,好像出了什么问题。。我的代码怎么了Php Laravel无法识别模型,php,mysql,laravel,laravel-4,Php,Mysql,Laravel,Laravel 4,我刚开始尝试Laravel,但我遇到了一些问题,尤其是在使用用户模型时。在我尝试使用用户模型访问数据库并在视图中显示条目之前,指南中的所有内容都对我有效。当我试图在浏览器中访问public/users/时,我遇到一个页面,上面写着,哇,好像出了什么问题。。我的代码怎么了 我已经用正确的用户名/pw设置了数据库 我使用migrate命令创建了一个名为“users”的表 该表已填充了几个条目 我还有一个视图文件,users.blade.php,如下所示: @extends('layout') @
- 我已经用正确的用户名/pw设置了数据库
- 我使用migrate命令创建了一个名为“users”的表
- 该表已填充了几个条目
- 我还有一个视图文件,users.blade.php,如下所示:
@extends('layout') @section('content') @foreach($users as $user) <p>{{ $user->name }}</p> @endforeach @stop
- 下面是我的User.php模型:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
一切都取决于你的自动加载器。它可能无法找到有问题的类。你在composer.json中有什么?哦,是的,我应该补充一点,我已经尝试了以下命令:composer dump autoload和php artisan dump autoload,但这并没有解决问题。我还将添加composer.json文件。您是否已打开调试模式?在app.php配置文件中,将debug设置为true以获取更详细的错误消息谢谢提示!我想知道如何获得更多有用的错误消息。它的意思是:拒绝用户“@'localhost”访问数据库“forge”。问题是我只使用用户名/pw更改了app/config/local/database.php文件,而没有更改app/config/database.php文件。现在它工作了,谢谢!伟大的很高兴这有帮助
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
}
class User extends Eloquent {}
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}