Suppose we have models A, and B and we need to choose which one of them to instantiate based on the information posted from the view.
Would it be a good practice to do something like this:
// ...
$data = $request()->get('model'); // <-- contains: $data['id'] and $data['class_name']
$id = $data['id'];
$class_name = $data['class_name'];
$$class_name::find($id); // <-- notice, that we are using POST-ed 'class_name' to determine which model we want to use!
// ...
Or can this approach introduce some problems in the future?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire