5

I have changed the primary key in a table from id to pr_id and mobile.


$table->primary(['pr_id' , 'mobile']);

also I added SoftDelete Trait in model. but when I want to delete a record it doesn't work.

ali Falahati
  • 599
  • 7
  • 18

2 Answers2

3

I believe this is because of not mentioning primary key into model, and your model still consider primary key is id however you have changed it. So you just to add following script into relevant model,

class YourModelClass extends Model
{
     protected $primaryKey = 'pr_id';
}

This in way model won't consider primary key as id.

Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68
1

You need to override few methods also like getKeyForSaveQuery, setKeysForSaveQuery with defining the primary key in model. For soft delete you need to override one more method runSoftDelete.

Reference links

Kamal Paliwal
  • 1,251
  • 8
  • 16