php - Laravel hasOne Huge Array -
i cant seem pull out cat name model.
my array looks fine when items below.
$testing = scrapper::get(); print_r($testing); [items:protected] => array ( [0] => scrapper object ( ..... [attributes:protected] => array ( [id] => 1 [cat_id] => 1 [created_at] => 2014-08-18 09:08:54 [updated_at] => 2014-08-18 09:08:54 ..... )
when try code bellow print_r huge array of nothing related pulling item it's categories name?
scrapper::first()->categorie();
illuminate\database\eloquent\relations\hasone object ( [foreignkey:protected] => categories.scrapper_id [localkey:protected] => id [query:protected] => illuminate\database\eloquent\builder object ( [query:protected] => illuminate\database\query\builder object ( .....
have done wrong, models below.
cat.php
class cat extends eloquent { protected $table = 'categories'; }
scrapper.php
class scrapper extends eloquent { protected $table = 'scrapper'; public function categorie() { return $this->hasone('cat'); } }
databases
categories - | id | name scrapper - |id | cat_id | updated_at | created_at
many thanks,
you need call:
scrapper::first()->categorie;
instead of:
scrapper::first()->categorie();
explanation: http://laravel.com/docs/eloquent#dynamic-properties
Comments
Post a Comment