class Item { private $id; public function __construct($id) { $this->id = $id; } public function getId() { return $this->id; } } $item1 = new Item(1); $item2 = new Item(2); echo $item1->getId(); //output: 1 echo $item2->getId(); //output: 2
use Illuminate\Database\Eloquent\Model; class Item extends Model { } $item = Item::find(1); echo $item->getId(); //output: 1In this code example, the Item class extends the Model class from the Laravel framework, which provides a getId method to retrieve the id attribute. An instance of the Item class is retrieved using the find method from the Model class. Package library: Laravel Eloquent ORM.