Good morning everyone,
I'm developing an application in Laravel 5.6 using PHP 7.2, I'm having problems using the dependency injection in the constructor, since when creating the object the algorithm works perfectly,
This DOES NOT work:
CentralController
<?php
namespace App\Http\Controllers;
use App\Models\Central;
class CentralController extends BaseController
{
protected $central;
public function __construct(Central $central)
{
$this->central = $central;
}
public function centralParser(Request $request)
{
$this->central->cadastrarDados($request->all());
...
}
BaseController
namespace App\Http\Controllers;
use App\Models\Usuario;
class BaseController extends ResponseController
{
protected $usuario;
public function __construct(Usuario $usuario)
{
$this->usuario = $usuario;
}
//metodos......
}
This Works:
CentralController
<?php
namespace App\Http\Controllers;
use App\Models\Central;
class CentralController extends BaseController
{
public function centralParser(Request $request)
{
$central = new Central();
$central->cadastrarDados($request->all());
...
}
}
BaseController
namespace App\Http\Controllers;
use App\Models\Usuario;
class BaseController extends ResponseController
{
protected $usuario;
public function __construct(Usuario $usuario)
{
$this->usuario = $usuario;
}
//metodos......
}