Problem. When I instantiate an class object from an another namespace (within my controller) I get this error:
ReflectionException in Container.php line 794:
Class App\Library\Transformers\LessonTransformer does not exist
Any ideas what could be wrong?
App\Http\Controllers\LessonsController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use App\Library\Transformers\Transformer;
use App\Library\Transformers\LessonTransformer;
use App\Http\Requests;
use App\Lesson;
class LessonsController extends Controller{
protected $lessonTransformer;
function __construct(LessonTransformers $lessonTransformer)
{
$this->lessonTransformer = $lessonTransformer;
}
//
public function index()
{
$lessons = Lesson::all();
return Response()->json([
'data' => $this->lessonTransformer->transformCollection($lessons->all() )
], 200);
}
public function show($id)
{
$lesson = Lesson::find($id);
if ( ! $lesson )
{
return Response()->json([
'error' => [
'message' => 'Lesson does not exist'
]
], 404);
}
} }
App\Library\Transformers\LessonTransformer
<?php
namespace App\Library\Transformers;
public class LessonTransformer extends Transformer {
public function transform($lesson)
{
return [
'title' => $lesson['title'],
'body' => $lesson['body'],
'active' => (boolean) $lesson['some_bool']
];
}
}
App\Library\Transformers\Transformer
<?php
namespace App\Library\Transformers;
public abstract class Transformer {
public function transformCollection(array $item)
{
return array_map([$this, 'transform'], $item->toArray());
}
public abstract function transform($item);
}
Composer.json
I have also tried to change composer.json like this, but without success:
"autoload": {
"classmap": [
"database",
"App/Library"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php",
"App/Library"
]
},
Sidenote. I am using Laravel 5.2.



LessonTransformersnot have the trailings? Don't think this explains the error though.new LessonTransformers()?