If my thoughts are correct. You want to include methods from another model into a seperate model...
In this case, you can use the __construct method in your model that is extending the external class:
private $external;
public function __construct(ExternalClass $external)
{
$this->external = $external;
}
then, in other methods in the class that is extending the ExternalClass, you can call the method with:
public function thingDoer()
{
return $this->external->thingThatDoes();
}
Code not tested so let me know if this helps!
Edit: I think in php5.4+ you may need to use:
class Model extends Eloquent {
use External;
public function thingDoer()
{
return $this->thingThatDoes();
}
}
class External {
public function thingThatDoes(){ return $something };
}
There are a few ways to do this, but it depends on how your personal project is structured. Try to stay consistent with your practices.
class External { public function thingThatDoes(){ return $something }; }
You mean ... ;)
trait External { ... }
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community