kristijanhusak / laravel-form-builder

Laravel Form builder for version 5+!
https://packagist.org/packages/kris/laravel-form-builder
MIT License
1.69k stars 298 forks source link

I am getting an error while installing. (ide-helper / composer) #628

Closed mertasan closed 3 years ago

mertasan commented 3 years ago

I'm getting an error installing with Composer

Laravel version: 8.x

% COMPOSER_MEMORY_LIMIT=-1 composer require kris/laravel-form-builder       
Using version ^1.40 for kris/laravel-form-builder
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package fzaninotto/faker is abandoned, you should avoid using it. No replacement was suggested.
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: awobaz/compoships
Discovered Package: barryvdh/laravel-debugbar
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: jenssegers/agent
Discovered Package: kris/laravel-form-builder
Discovered Package: laravel/fortify
Discovered Package: laravel/jetstream
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: laravelcollective/html
Discovered Package: livewire/livewire
Discovered Package: maatwebsite/excel
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: staudenmeir/laravel-cte
Discovered Package: yajra/laravel-datatables-buttons
Discovered Package: yajra/laravel-datatables-editor
Discovered Package: yajra/laravel-datatables-fractal
Discovered Package: yajra/laravel-datatables-html
Discovered Package: yajra/laravel-datatables-oracle
Package manifest generated successfully.
95 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> Illuminate\Foundation\ComposerScripts::postUpdate
> @php artisan ide-helper:generate

   TypeError 

  Argument 3 passed to Kris\LaravelFormBuilder\FormHelper::__construct() must be of the type array, null given, called in /Users/[my project path]/vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php on line 65

  at vendor/kris/laravel-form-builder/src/Kris/LaravelFormBuilder/FormHelper.php:97
     93▕      * @param View    $view
     94▕      * @param Translator $translator
     95▕      * @param array   $config
     96▕      */
  ➜  97▕     public function __construct(View $view, Translator $translator, array $config = [])
     98▕     {
     99▕         $this->view = $view;
    100▕         $this->translator = $translator;
    101▕         $this->config = $config;

      +36 vendor frames 
  37  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Script @php artisan ide-helper:generate handling the post-update-cmd event returned with error code 1

composer.json


    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "@php artisan ide-helper:generate",
            "@php artisan ide-helper:meta",
            "@php artisan ide-helper:models --dir=\"app/Models\" --write-mixin"
        ]
    }

Edit: I solved it like this.

  1. I created the config file named config/laravel-form-builder.php
  2. I added the settings here to the file. config.php

reference

rudiedirkx commented 3 years ago

Could you get a trace? It happens on FormHelper.php:97 because config is probably null, but why? FormBuilderServiceProvider::register() registers the config file, so it should always be an array, even without publishing/copying it to your own config dir. It seems like ide-helper is too fast? Or Laravel doesn't do a register() for unknown packages, but ide-helper still tries to. Dunno.

I think form builder does what it's supposed to. Ide-helper is too eager, or Laravel too lazy. You'll have to debug it. A trace would help. Maybe you don't have to keep uninstalling and installing the package. ide-helper:generate without FormBuilderServiceProvider listed might be enough.

mertasan commented 3 years ago

It was working smoothly. After installing I ran the ide-helper commands manually and they worked without any problems. It can be as you said. I cannot catch any other error / trace other than the console error I added to my previous post.

rudiedirkx commented 3 years ago

It was working smoothly. After installing I ran the ide-helper commands manually and they worked without any problems.

I expected that. But it should have worked with the ide commands in composer.json too. I've never seen it, so I wouldn't know how to start finding and fixing the problem. If you're willing, please do. If it's this package's fault, we'd love to know.