Answer the question
In order to leave comments, you need to log in
How to edit information in the database through a method?
Guys, I need help. There is a product. At it for example four fields in a DB. ID, name, price, description. The Product class has setName(id, name), setPrice(id, price), setDescription(id, text) methods.
Previously, I created a general update method and added an associative array with keys (id, price, name, description) there, but over time I realized that you can expand only by editing the main class, and this contradicts the oop principle.
How to correctly build the logic for editing a product using these four fields as an example?
Three ways came to mind:
1. Leave it as it is and change ONE value AT ONCE (the downside is that you have to submit for each field in the form)
2. Accept an associative array and edit in one update method.
3. Write an intermediate method that, based on an associative array, will assemble a construction like
$obj->setId($id);
$obj->setName($name);
$obj->setPrice($price);
$obj->Update();
Answer the question
In order to leave comments, you need to log in
read about ORM. Eloquent for example laravel.su/docs/5.2/eloquent
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question