-
Hello everyone, Is there a way to query on database inside a vendor package using Reflection API? // VendorPackage/Foo.php
class Foo {
// $model is a Model class in App\\Models\\ namespace
public function bar(string $model)
{
$reflection = new \ReflectionClass($model);
\call_user_func(sprintf('%s::all', $reflectionClass->getName())
} But actually this is not working because the connection is null at this point. I want to access to the model only after attributes (like the table name) are filled. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I’m not sure about the reflection approach either. Do you have a reason why you don’t just send the model object to this method? |
Beta Was this translation helpful? Give feedback.
-
I'm not even sure what you are trying to do. Are you using Orchestra testbench in your tests? besides, you don't need the Reflection API. You can just call |
Beta Was this translation helpful? Give feedback.
-
Thank you. |
Beta Was this translation helpful? Give feedback.
I'm not even sure what you are trying to do. Are you using Orchestra testbench in your tests?
besides, you don't need the Reflection API. You can just call
$model::all();
after checking if the string is a model using is_subclass_of