teepluss / laravel-theme

Theme and asset managing for laravel
MIT License
546 stars 132 forks source link

Using theme global, need to implement Dependency injection in all subclass? #109

Closed nhim175 closed 9 years ago

nhim175 commented 9 years ago

I followed the example in Using theme global section.

Whenever I create a subclass of BaseController class, seems like I have to do something like this:

class AnotherController extends BaseController {
  public function __construct(Theme $theme) {
    parent::__construct($theme);
    ...
  }
}

Is there any better way?

teepluss commented 9 years ago

namespace App\Http\Controllers\Demo;

use App\Http\Controllers\Controller;
use Teepluss\Theme\Contracts\Theme;

class ThemeController extends Controller
{
    public function __construct(Theme $theme)
    {
        $this->theme = $theme->uses('default');
    }

    public function getIndex()
    {
        return $this->theme->scope('theme.index')->render();
    }
}