Reputation: 8321
I want to create a custom function inside my model in order to retrieve data with more compicated queries but I get an error that my method is undefined.
//Model
class Host extends Eloquent {
//custom function
//or public static function
public function allWithUser() {
}
}
//Controller
//or Host::allWithUser();
$hosts = with(new Host)->allWithUser();
Upvotes: 0
Views: 487
Reputation: 87789
You have some options to access this method, but I think those you shown to us are not right. Those (non static) ways you might be successful:
$hosts = (new Host)->allWithUser();
and
$hosts = new Host;
$hosts->allWithUser();
But your static version should have worked.
EDIT
If it does not work, you must be instantiating a different version of the Host class.
Change the model class name from ´Host´ to ´HostTest´ and check if
$hosts = new Host;
Still works for you.
EDIT 2
If you find you have two classes using the same name, you can check the file
vendor/composer/autoload_classmap.php
All your autoloaded classes should be listed there.
And if you are on a Linux, you can
find /your/app/path | grep Host.php
and
sudo grep -r "class Host" /your/app/path/*
Upvotes: 1