我正在与一个破碎的工匠打交道。每次我运行任何迁移命令时,它都会说:
[ErrorException]
Undefined property: Illuminate\Database\Query\Builder::$projects
无论我是否删除项目表和模型,它都无法再次运行迁移命令。我已经在用户和项目之间创建了一个关系,一个用户可以有很多项目,自从引入它之后,我的整个应用程序似乎都坏了。像Auth::check()
给出同样的错误。
项目模型:
class Projects extends Eloquent {
public function user() {
return $this->belongsTo("User");
}
public function android_app_entries() {
return $this->hasMany("AndroidAppEntries");
}
}
用户型号:
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
protected $table = 'users';
public static $rules = array(
'username'=>'required|between:6,18',
'password'=>'required|between:6,18',
'project_id'=>'required'
);
// Artist __has_many__ projects
public function projects()
{
return $this->hasMany('Projects');
}
项目迁移文件:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProjectsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('projects', function($table) {
$table->increments('id');
$table->string('project_name');
$table->string('client_name');
$table->integer('users_id');
$table->foreign('users_id')->references('id')->on('users');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('projects');
}
用户迁移文件:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function($table){
$table->increments('id');
$table->string('username');
$table->string('password', 64);
$table->string('role');
$table->string('remember_token');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
我希望其他人也经历过这种情况,并且可以帮助我。
另一个注意事项:我重命名了由工匠创建的控制器。不确定这是否有任何影响。作曲家是否转储自动加载以确保..
更新:
即使在完全删除所有模型和完整数据库之后,错误仍然存在。我什至回滚到今天下午工作的代码,没有今晚的变化。所以我的猜测是整个安装有问题..
laravel.log:
[2015-01-29 21:29:03] local.ERROR: exception 'ErrorException' with message 'Undefined property: Illuminate\Database\Query\Builder::$projects' in /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php:56
Stack trace:
#0 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php(56): Illuminate\Exception\Handler->handleError(8, 'Undefined prope...', '/var/www/larave...', 56, Array)
#1 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php(38): Illuminate\Database\Query\Grammars\Grammar->compileComponents(Object(Illuminate\Database\Query\Builder))
#2 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php(34): Illuminate\Database\Query\Grammars\Grammar->compileSelect(Object(Illuminate\Database\Query\Builder))
#3 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1234): Illuminate\Database\Query\Grammars\MySqlGrammar->compileSelect(Object(Illuminate\Database\Query\Builder))
#4 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1359): Illuminate\Database\Query\Builder->toSql()
#5 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1349): Illuminate\Database\Query\Builder->runSelect()
#6 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1336): Illuminate\Database\Query\Builder->getFresh(Array)
#7 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1771): Illuminate\Database\Query\Builder->get(Array)
#8 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(1731): Illuminate\Database\Query\Builder->aggregate('max', Array)
#9 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php(105): Illuminate\Database\Query\Builder->max('batch')
#10 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Migrations/DatabaseMigrationRepository.php(58): Illuminate\Database\Migrations\DatabaseMigrationRepository->getLastBatchNumber()
#11 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(158): Illuminate\Database\Migrations\DatabaseMigrationRepository->getLast()
#12 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Database/Console/Migrations/ResetCommand.php(61): Illuminate\Database\Migrations\Migrator->rollback(false)
#13 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Console/Command.php(112): Illuminate\Database\Console\Migrations\ResetCommand->fire()
#14 /var/www/laravel-develop/vendor/symfony/console/Symfony/Component/Console/Command/Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#15 /var/www/laravel-develop/vendor/laravel/framework/src/Illuminate/Console/Command.php(100): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#16 /var/www/laravel-develop/vendor/symfony/console/Symfony/Component/Console/Application.php(889): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#17 /var/www/laravel-develop/vendor/symfony/console/Symfony/Component/Console/Application.php(193): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Database\Console\Migrations\ResetCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#18 /var/www/laravel-develop/vendor/symfony/console/Symfony/Component/Console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#19 /var/www/laravel-develop/artisan(59): Symfony\Component\Console\Application->run()
#20 {main} [] []