Skip to content

Instantly share code, notes, and snippets.

@anthonybudd
Last active May 16, 2017 16:10
Show Gist options
  • Select an option

  • Save anthonybudd/1c7ee27f778e0004c08b8c072391cf86 to your computer and use it in GitHub Desktop.

Select an option

Save anthonybudd/1c7ee27f778e0004c08b8c072391cf86 to your computer and use it in GitHub Desktop.
<?php
Class Product{
...
public $virtual = [
'humanWeight',
'seller',
];
public function _getHumanWeight(){
return $this->weight . 'Kg';
}
public function _getSeller(){
return Seller::find($this->seller_id);
}
}
$product = Product::find(10);
$productWeight = $product->humanWeight; // '10Kg'
$productSellerName = $product->seller->full_name; // 'John Doe'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment