Is it possible to define primaryKey on runtime for Laravel / Eloquent? -
in eloquent, know it's possible define table on runtime $model->settable().
i tried adding new item in constructor like:
$mymodel = new \mymodel(array(), 'my_primary_key'); $mymodel->settable('mytable'); with constructor being:
class mymodel extends eloquent { public function __construct($attributes = array(), $primarykey = 'id') { parent::__construct($attributes); // eloquent $this->primarykey = $primarykey; } } that makes $primarykey = 'id' default. - 1 doesn't work cause doesn't change primarykey whatever define in call constructor, gets default ('id'). if don't set default following error:
missing argument 3 mymodel::__construct(), called in /vendor/laravel/framework/src/illuminate/database/eloquent/model.php on line 517 , defined i tried:
$mymodel->setattribute('primarykey', 'my_primary_key'); but 1 doesn't set attribute
but nothing works. default laravel having 'id' primarykey, in tables have things 'car_id' table cars, , on, errors like:
column not found: 1054 unknown column 'id' in 'where clause' (sql: select * `cars` `id` = 1 limit 1) i tried code: https://github.com/laravel/framework/blob/master/src/illuminate/database/eloquent/model.php#l1415, doesn't have method set on runtime.
Comments
Post a Comment