0
我試圖挽救註冊用戶時多態性關係的多態關係的時候,但它返回我:調用未定義生成器::保存()保存
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');
}
}
每當我嘗試註冊某人時,它都會返回this error。
如果有人能告訴我我做錯了什麼,那該多好。謝謝。 :)
更新
改變了我的模型保存到:
$alumno->save();
$usuario->save();
$usuario->cuenta()->save($alumno);
它返回 調用未定義的方法照亮\數據庫\查詢\生成器::保存()
還用於:
$alumno->save();
$usuario->save();
$usuario->cuenta()->associate($alumno);
它返回
Maximum function nesting level of '100' reached, aborting!
我應該使用FK?
你的意思是做$ usuario->保存()();那麼這個$ usuario-> cuenta() - >保存($ alumno); ? – aerojun