1

I've got a BaseController in a Laravel Framework based App with the following code:

class BaseController extends Controller {
    public function __construct(Credentials $credentials) {
      $this->credentials = $credentials;
}

Then, all my other controllers will Extend the BaseController:

class PostController extends BaseController {
public function __construct(PostRepository $post)
{
    $this->post = $post;
    parent::__construct();
}

However, I'd need to type hint the Credentials Class in the parent::__construct(); of all my controllers. Is there any way to avoid that?

Thanks in advance

Tenzoru
  • 953
  • 1
  • 8
  • 9

1 Answers1

1

I can solve it using the following code:

class BaseController extends Controller {    

public function __construct()
{
    $this->credentials = App::make('Credentials'); // make sure to use the fully qualified namespace of Credentials if need be
}
}
Tenzoru
  • 953
  • 1
  • 8
  • 9