iberflow / laravel-model-generator

Laravel 5 model generator for an existing schema
264 stars 76 forks source link

Request: Primary Key Detection #14

Closed ghost closed 8 years ago

ghost commented 8 years ago

Determine if primary key is the standard id or not.

If not, create primary key property and remove the primary key field from the $fillable array.

Example:

CREATE TABLE `order_product` (
  `order_product_id` int(11) NOT NULL AUTO_INCREMENT,
  `order_id` int(11) NOT NULL,
  `product_id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `model` varchar(64) NOT NULL,
  `quantity` int(4) NOT NULL,
  `price` decimal(15,4) NOT NULL DEFAULT '0.0000',
  `total` decimal(15,4) NOT NULL DEFAULT '0.0000',
  `tax` decimal(15,4) NOT NULL DEFAULT '0.0000',
  `reward` int(8) NOT NULL,
  PRIMARY KEY (`order_product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Would produce:

protected $primaryKey = 'order_product_id';

protected $fillable = [
    'order_id',
    'product_id',
    'name',
    'model',
    'quantity',
    'price',
    'total',
    'tax',
    'reward'
];
iberflow commented 8 years ago

Unfortunately I don't have much time until next month, therefore I'd love a pull request for this:)

iberflow commented 8 years ago

ah, actually this has been fixed with #16