php - Including View Composers in Laravel using Composer -


i have made below composer view app. i've placed in separate file @ app/composers.php.

<?php  // namespace app\modules\manager\composer; // use illuminate\support\facades\view view ;  /* |-------------------------------------------------------------------------- | composers |-------------------------------------------------------------------------- | | */   view::composer('tshop.includes.header', function($view) {      $categories = categories::getwithchilds();      $view->withcategories( $categories);  }); 

my composer.php file

"autoload": {     "classmap": [         "app/commands",         "app/controllers",         "app/models",         "app/database/migrations",         "app/database/seeds",         "app/tests/testcase.php"     ],     "files": [         "app/composers.php"     ] }, 

unfortunately error

fatal error: class 'view' not found in c:\xampp\htdocs\eshop\app\composers.php on line 15 

update

i tried this. wrote inside app/start/global.php

require app_path().'/composers.php'; 

and

use illuminate\support\facades\view view ; 

at app/composers.php, getting error

fatal error: call member function composer() on non-object in c:\xampp\htdocs\eshop\vendor\laravel\framework\src\illuminate\support\facades\facade.php on line 211

as @theshiftexchange found out, 1 problem used "files" options.

as can see in composer's code, autoload section corresponds this:

class composerautoloaderinitf8489489s7f894ds98f47d {     ....     ....     public static function getloader()     {         ....         ....         $includefiles = require __dir__ . '/autoload_files.php';         foreach ($includefiles $file) {             composerrequiref4s65f4556sd4f564fsdfd($file);         }          return $loader;     } }  function composerrequire5894s89f4sd98498489f7b37d($file)  {     require $file; } 

so files array specify required during composer's autoload process, way before view facade loaded.

the providers facades loaded in vendor/laravel/framework/illuminate/foundation/start.php

/* |-------------------------------------------------------------------------- | register core service providers |-------------------------------------------------------------------------- | | illuminate core service providers register of core pieces | of illuminate framework including session, caching, encryption | , more. it's convenient wrapper registration. | */  $providers = $config['providers'];  $app->getproviderrepository()->load($app, $providers); 

actually, problem classmaps other one: no class in file, file never loaded doesn't anything.

to make work, should add app/start/global.php @ end of file:

instead of

require app_path() . '/filters.php'; 

write

require app_path() . '/composers.php'; require app_path() . '/filters.php'; 

that's best way can think of include files @ each load of application not classes.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -