Back to blog

Fix TwigBridge and Laravel 4.2


As you may have noticed TwigBridge 5.* doesn’t work well with Laravel 4.2.


PHP Fatal error: Class 'Illuminate\View\Environment' not found

I had to update to Laravel 4.2 because of the Queue improvements so it wasn’t something that could wait.

In Laravel 4.1.15 the Environment classes have been renamed from Environment to Factory. That breaks with TwigBridge.


After some debugging it’s quite easy to upgrade as the TwigBridge developer has a 0.6 branch in development.

Open your composer.json file and change the required packages to your need:


...
"require": {
            "laravel/framework": "4.2.*",         
            "rcrowe/twigbridge": "0.6.*"
	},
...

Laravel has now the 4.2.* version and TwigBridge the 0.6.* version.
If you do a composer update it likely will fail because it can’t find the 0.6 version of TwigBridge.
You can solve this in 2 ways:

1 (preferred). Instead of adding a version number you could add “dev-master@dev” so you’ll always get the latest dev branch.


...
"require": {
            ...
            "rcrowe/twigbridge": "dev-master@dev"
	    ...
	},
...

2. You can put in the following to the root of your composer.json file:


...
"minimum-stability": "dev",
"prefer-stable": true
...

This will however, use a dev version (if there is any) for all your packages. If composer can’t find a dev version it will
use the stable one.

Once you’ve saved your new composer.json file run the following from within your Laravel application:


composer update

Run:


php artisan config:publish rcrowe/twigbridge

to publish its new configuration.

Sources:
TwigBridge: https://github.com/rcrowe/TwigBridge/tree/0.6
Twitter: https://twitter.com/laravelphp/status/422772763862913025

Labels: composer twig twigbridge

Drop a note