Created
April 13, 2017 14:01
-
-
Save raphox/f1019242075faeccdb18501fd1b68f2b to your computer and use it in GitHub Desktop.
Laravel provider to inlude javascript files on blade view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\View\Factory as FactoryContract; | |
class Factory extends FactoryContract | |
{ | |
/** | |
* The extension to engine bindings. | |
* | |
* @var array | |
*/ | |
protected $extensions = [ | |
'blade.php' => 'blade', | |
'php' => 'php', | |
'css' => 'file', | |
'js' => 'file', | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\Providers\Factory; | |
use Illuminate\View\FileViewFinder; | |
use Illuminate\View\ViewServiceProvider as ServiceProvider; | |
class ViewServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register the view environment. | |
* | |
* @return void | |
*/ | |
public function registerFactory() | |
{ | |
$this->app->singleton('view', function ($app) { | |
// Next we need to grab the engine resolver instance that will be used by the | |
// environment. The resolver will be used by an environment to get each of | |
// the various engine implementations such as plain PHP or Blade engine. | |
$resolver = $app['view.engine.resolver']; | |
$finder = $app['view.finder']; | |
$env = new Factory($resolver, $finder, $app['events']); | |
// We will also set the container instance on this view environment since the | |
// view composers may be classes registered in the container, which allows | |
// for great testable, flexible composers for the application developer. | |
$env->setContainer($app); | |
$env->share('app', $app); | |
return $env; | |
}); | |
} | |
/** | |
* Register the view finder implementation. | |
* | |
* @return void | |
*/ | |
public function registerViewFinder() | |
{ | |
$this->app->bind('view.finder', function ($app) { | |
$extensions = ['blade.php', 'php', 'css', 'js']; | |
return new FileViewFinder($app['files'], $app['config']['view.paths'], $extensions); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment