Skip to content

Instantly share code, notes, and snippets.

@raphox
Created April 13, 2017 14:01
Show Gist options
  • Save raphox/f1019242075faeccdb18501fd1b68f2b to your computer and use it in GitHub Desktop.
Save raphox/f1019242075faeccdb18501fd1b68f2b to your computer and use it in GitHub Desktop.
Laravel provider to inlude javascript files on blade view
<?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',
];
}
<?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