Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

Did you already tried $mydata = Event; ?

0

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()

Last updated 8 years ago.
0

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.

0

Maybe try this?

$className = "Link";
$results = {$className}::all();
0

fetch404 said:

Maybe try this?

$className = "Link";
$results = {$className}::all();

Thanks, but it's not liking the opening {

syntax error, unexpected '{'

0

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();
0

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
Last updated 8 years ago.
0

As for this problem - I don't know solution. I just included namespace before every class :)

0

ModestasV said:

As for this problem - I don't know solution. I just included namespace before every class :)

Thank you very much :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

dfc1883 dfc1883 Joined 21 Jun 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.