Hello!
I'm working in a Laravel project and I created all the structure like repository, services, etc. But, when in the controller I call the service in the constructor with dependency injection and then starts the application, the web crash.
ReflectionException in Container.php line 809:
Class app\Services\UserService does not exist
In ASP .NET MVC, for dependency injection we have tools like Autofac, when you tells to application that have to initializate the class/service before you injects it. But in Laravel I didn't found something like this.
I look the code and I think that all is correct, so, I don't know where is the problem.
Controller:
<?php
namespace App\Http\Controllers;
use app\Services\UserService;
class UserController extends ProjectController
{
protected $user;
public function __construct(UserService $user)
{
$this->user = $user;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('users.index');
}
}
Servicio
<?php
namespace app\Services;
use app\Repositories\UserRepository;
class UserService
{
protected $user;
public function __construct(UserRepository $user)
{
$this->user = $user;
}
public function all()
{
return $this->servicio->all();
}
}
Repositorio
<?php
namespace app\Repositories;
use App\User;
class UserRepository
{
protected $user;
public function __construct(User $user)
{
$this->user = $user;
}
public function all()
{
return $this->user->all();
}
}
Also, I tried something like composer dump-autoload and composer update but doesn't work.
Thanks