1

Suppose, I have these ardent models

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';         
}

Now, when I write a controller code like this,

 $user = new User;
 $user->address = Input::get('address');
 $user->push();

It doesn't save the address data to address table

Vishwajeet Vatharkar
  • 1,146
  • 4
  • 18
  • 42

1 Answers1

0

You don't show the Party model?

Furthermore, Input::get('address') does nothing, it just returns the address from the input.

I'm assuming here, but I suppose you'd want something like this:

$user = new User;
$user->locations()->create(Input::only('address'));

That will create a new location for the user, passing in the address from the input.


If you're trying to use Ardent's autohydration, this might do the trick:

// Autohydrate the location model with input.
$location = new Location;

// Associate the new model with your user.
$user->locations()->save($location);
Dwight
  • 12,120
  • 6
  • 51
  • 64
  • Hi @Dwight, I made necessary corrections in my question. And I used `$user->locations()->create(Input::only('address'));` as you suggested. But I'm using autohydration (ardent feature) and I thought I do not need to do this manually. It is still not working as expected. – Vishwajeet Vatharkar Aug 25 '14 at 09:05
  • I'm not totally familiar with Ardent, but I've updated my answer with something that might do the trick. – Dwight Aug 26 '14 at 02:05