Search code examples
laravellaravel-5composer-phplaravel-formlaravelcollective

Laravel 5: Installing Form and HTML classes without composer


I'm interested in installing Form and HTML classes on Laravel 5 without composer. How can I do this?

For those wanting to convince me to use composer:

1) I want to see what it does by doing it manually myself at least once.

2) There is no composer on my hosting.

3) Using composer.phar throws an error: Script php artisan clear-compiled handling the pre-update-cmd event returned with an error, gives a warning: Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI and runtime exception with blank error output.


Solution

  • Installing laracollective/html:

    1) Download zip package from extension's git repository

    2) Unpack contents and create this directory structure: laravelcollective/html/{contents of html-5.1 directory}

    3) Copy this structure to the vendor folder in your Laravel installation.

    4) In vendor/composer/autoload_classmap.php add these lines

    'Collective\\Html\\FormBuilder' => $vendorDir . '/laravelcollective/html/src/FormBuilder.php',
    'Collective\\Html\\FormFacade' => $vendorDir . '/laravelcollective/html/src/FormFacade.php',
    'Collective\\Html\\HtmlBuilder' => $vendorDir . '/laravelcollective/html/src/HtmlBuilder.php',
    'Collective\\Html\\HtmlFacade' => $vendorDir . '/laravelcollective/html/src/HtmlFacade.php',
    'Collective\\Html\\HtmlServiceProvider' => $vendorDir . '/laravelcollective/html/src/HtmlServiceProvider.php',
    

    after

        'ClassPreloader\\Parser\\NodeTraverser' => $vendorDir . '/classpreloader/classpreloader/src/Parser/NodeTraverser.php',
    

    so that Laravel knows where to look for these classes when requested.

    5) Add this line as a last element to return array(...) in vendor/composer/autoload_files.php

    $vendorDir . '/laravelcollective/html/src/helpers.php',
    

    6) Add this line to return array(...) in vendor/composer/autoload_psr4.php

    // 'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
    'Collective\\Html\\' => array($vendorDir . '/laravelcollective/html/src'),   
    // 'ClassPreloader\\' => array($vendorDir . '/classpreloader/classpreloader/src'),
    

    7) Add providers to providers array of config/app.php:

    'providers' => [
    // ...
    Collective\Html\HtmlServiceProvider::class,
    // ...
    

    ],

    8) Add two class aliases to the aliases array of config/app.php:

    'aliases' => [
    // ...
      'Form' => Collective\Html\FormFacade::class,
      'Html' => Collective\Html\HtmlFacade::class,
    // ...
    

    ],

    References:

    http://laravelcollective.com/docs/5.1/html