PHP laravel class not found. How can I use namespaces to fix this?
I'm using the Laravel framework and have a directory of the following structure:
models
Statistic.php
presenters
StatisticPresenter.php
In mymodels/Statistic
class, I'm trying to access apresent
method which calls a protected property which then references my presenter:
protected $presenter = 'presenters\StatisticPresenter';
public function present() {
return new $this->presenter($this);
}
Yet, this returns the error:Class 'presenters\StatisticPresenter' not found
. I realize this is a namespacing error of some sort, and I've tried watching a few videos on how it works, but I simply can't wrap my head around it. I have already added my presenter folder to mycomposer.json
file. For example, adding this to the top of myStatistic
model does not work:
use presenters\StatisticPresenter;
How can I fix this?
Answer
Solution:
Do the followings;
{ "autoload": { "psr-4": { "presenters\\": "app/presenters/" } } }