保存多态关系时调用未定义的Builder::save()


Call to undefined Builder::save() when saving a polymorphic relationship

我试图在注册用户时保存多态关系,但它返回我:

Call to undefined method Illuminate'Database'Query'Builder::save()

我有3个表在我的数据库:

Schema::create('usuarios', function(Blueprint $table) {
    $table->increments('id');
    $table->string('nombreUsuario', 20);
    $table->string('password', 60);
    $table->string('email', 30);
    $table->string('remember_token', 100)->nullable();
    $table->integer('cuenta_id');
    $table->string('cuenta_type');
    $table->timestamps();
});
Schema::create('empresas', function(Blueprint $table) {
    $table->increments('id');
    $table->string('nombreEmpresa', 50);
    $table->string('direccion', 50);
    $table->timestamps();
});
Schema::create('alumnos', function(Blueprint $table) {
    $table->increments('id');
    $table->string('nombre', 50);
    $table->string('apellidoPaterno', 50);
    $table->string('apellidoMaterno', 50);
    $table->integer('semestre');
       $table->timestamps();
});

在我的控制器上,当用户正在注册时:

$alumno = new Alumno;
$alumno->nombre             = Input::get('nombre');
$alumno->apellidoPaterno    = Input::get('paterno');
$alumno->apellidoMaterno    = Input::get('materno');
$alumno->semestre           = Input::get('semestre');
$alumno->save();
$usuario = new User;
$usuario->nombreUsuario     = Input::get('usuario');
$usuario->password      = Hash::make(Input::get('password'));
$usuario->email             = Input::get('email');
$usuario->cuenta()->save($alumno);  // <--Here

模型:

<?php
use Illuminate'Auth'UserInterface;
use Illuminate'Auth'Reminders'RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
 ...
    public function cuenta() {
        return $this->morphTo();
    }
}
<?php
class Alumno extends Eloquent {
    protected $fillable = [];
    public function user() {
        return $this->morphMany('User', 'cuenta');
   }    
}
<?php
class Empresa extends Eloquent {
    protected $fillable = [];
    public function user() {
        return $this->morphMany('User', 'cuenta');
    }
}

每次我尝试注册某人时,它都会返回这个错误。

如果有人能告诉我我做错了什么,那就太好了。谢谢。:)

更改了保存模型的方式:

$alumno->save();
$usuario->save();
$usuario->cuenta()->save($alumno);

它返回调用未定义方法Illuminate'Database'Query'Builder::save()

也使用:

$alumno->save();
$usuario->save();
$usuario->cuenta()->associate($alumno);
返回

Maximum function nesting level of '100' reached, aborting! 

我应该使用FK吗?

我想你改了

$usuario->cuenta()->save($alumno);

$usuario->save();

然后正常运行你的多态关系。

我做错了。(?)

改变
$usuario->cuenta()->save($alumno);

$alumno->user()->save($usuario);