假设,我有这些狂热的模型
class User extends 'LaravelBook'Ardent'Ardent
{
public $autoHydrateEntityFromInput = true;
protected $fillable = array('username', 'password', 'address');
protected $table = 'Users';
public static $relationsData = array(
'location' => array(self::HAS_ONE, 'Location');
}
class Location extends 'LaravelBook'Ardent'Ardent
{
protected $fillable = array('address');
protected $table = 'Locations';
}
现在,当我写这样的控制器代码时,
$user = new User;
$user->address = Input::get('address');
$user->push();
它不会将地址数据保存到地址表
您没有显示Party
模型吗?
此外,Input::get('address')
什么也不做,它只是从输入中返回地址。
我在这里假设,但我想你会想要这样的东西:
$user = new User;
$user->locations()->create(Input::only('address'));
这将为用户创建一个新的位置,从输入中传入地址。
<小时>如果你想使用Ardent的自动水合,这可能会奏效:
// Autohydrate the location model with input.
$location = new Location;
// Associate the new model with your user.
$user->locations()->save($location);
小时>