class User extends Model { protected $primaryKey = 'user_id'; public function getUserId() { return $this->getPk(); } }
class Product extends Model { protected $primaryKey = 'sku'; public function getSKU() { return $this->getPk(); } }In this example, the Product model has its primary key attribute set to 'sku'. The getSKU method returns the product's SKU by calling the getPk method. The getPk function is commonly used in PHP libraries that implement the Model-View-Controller (MVC) architecture, such as Laravel's Eloquent ORM or Yii's Active Record.