Thanks for the reply, yes, I've tried $mydata = Event; but I'm getting the error.
FatalErrorException in Facade.php line 207:
Call to undefined method Illuminate\Events\Dispatcher::all()
Thank you, however that only explains half of the problem though, so isn't quite the solution.
So 'Event' is a word that is already has an alias (so the original example is a bad one, and breaks for the wrong reason).
So I've tried using this instead.
$mydata = "Link";
$results = $mydata::all();
but I now get the error:
FatalErrorException in AdminController.php line 36:
Class 'Link' not found
but if I just call it as normal without the variable like this:
$results = Link::all();
This works, I get all the results from the Links table - so the class does exist, but it's not liking it when I try to pass it as a variable.
fetch404 said:
Maybe try this?
$className = "Link"; $results = {$className}::all();
Thanks, but it's not liking the opening {
syntax error, unexpected '{'
After I encountered this problem I just did like this:
$className = "MyClass"; // Include your namespace in here if you are calling this dynamicly
$class = new $className;
$results = $class::all();
ModestasV said:
After I encountered this problem I just did like this:
$className = "MyClass"; // Include your namespace in here if you are calling this dynamicly $class = new $className; $results = $class::all();
Thanks, that's just about it!, but I have a question....
So this works....
$className = "\App\Link";
$class = new $className;
$results = $class::all();
but because I've declared at the top of the page shouldn't this be possible?
use App\Link;
$className = "Link";
$class = new $className;
$results = $class::all();
... it does however error
Class 'Link' not found
As for this problem - I don't know solution. I just included namespace before every class :)
ModestasV said:
As for this problem - I don't know solution. I just included namespace before every class :)
Thank you very much :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community