Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install the package for Laravel 6.0 #2202

Closed
baig772 opened this issue Oct 2, 2019 · 14 comments · Fixed by #2240
Closed

Unable to install the package for Laravel 6.0 #2202

baig772 opened this issue Oct 2, 2019 · 14 comments · Fixed by #2240

Comments

@baig772
Copy link

baig772 commented Oct 2, 2019

ErrorException : Invalid argument supplied for foreach()

I tried running this command to install composer require yajra/laravel-datatables-oracle and I saw the below message

Using version ^9.7 for yajra/laravel-datatables-oracle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi

   ErrorException  : Invalid argument supplied for foreach()

  at /var/www/atd-inspector/vendor/yajra/laravel-datatables-oracle/src/DataTablesServiceProvider.php:45
    41|      */
    42|     public function boot()
    43|     {
    44|         $engines = config('datatables.engines');
  > 45|         foreach ($engines as $engine => $class) {
    46|             $engine = Str::camel($engine);
    47| 
    48|             if (! method_exists(DataTables::class, $engine) && ! DataTables::hasMacro($engine)) {
    49|                 DataTables::macro($engine, function () use ($class) {

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Invalid argument supplied for foreach()", "/var/www/atd-inspector/vendor/yajra/laravel-datatables-oracle/src/DataTablesServiceProvider.php", [])
      /var/www/atd-inspector/vendor/yajra/laravel-datatables-oracle/src/DataTablesServiceProvider.php:45

  2   Yajra\DataTables\DataTablesServiceProvider::boot()
      /var/www/atd-inspector/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:32

  Please use the argument -v to see more details.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Installation failed, reverting ./composer.json to its original content.

  • Operating System : Ubuntu 19.10
  • PHP Version: 7.3.9-1
  • Laravel Version : 6.0
  • Laravel-Datatables Version
@Slivicon
Copy link

Slivicon commented Oct 2, 2019

#2156

@yajra
Copy link
Owner

yajra commented Oct 3, 2019

Are you upgrading or using a fresh install? Try removing the existing config if you already published.

@sms1078
Copy link

sms1078 commented Oct 3, 2019

Same for me. I'm using laravel with debug and test mode (not production) in localhost.
Any solution?
Thx.

@sms1078
Copy link

sms1078 commented Oct 6, 2019

I solved editing vendor/yajra/laravel-datatables-oracle/src/DataTablesServiceProvider.php
editing $engines to:

$engines = [ 'eloquent' => Yajra\DataTables\Engines\EloquentEngine::class, 'query' => Yajra\DataTables\Engines\QueryBuilderEngine::class, 'collection' => Yajra\DataTables\Engines\CollectionEngine::class, // add your custom engine ];
And then make the command again

composer require yajra/laravel-datatables-oracle:"~9.0"

Then you need to add in confi/app.php the two lines as sayed in the installation post and then run the command:

php artisan vendor:publish --provider=Yajra\DataTables\DataTablesServiceProvider
And
php artisan config:cache

And works !!

@ahmadb-allshore
Copy link

Having the same issue. Any fix to this one yet?

@thejweiss
Copy link

It seems like it is an issue with automatic package discovery in Laravel. If you copy the datatables.php config file into the config directory in Laravel and then run php artisan config:clear it works. Seems like the package discovery is running the boot method before the config file is available to provide the engines array.

@ahmadb-allshore
Copy link

@yajra is there any fix coming for this?

@TWithers
Copy link

TWithers commented Nov 7, 2019

Was hoping to have a fix for this the past couple weeks. Editing /vendor files with static content from a config file is a work-around, but not a fix.

@yajra
Copy link
Owner

yajra commented Nov 8, 2019

Will review and try to replicate the issue.

@yajra
Copy link
Owner

yajra commented Nov 8, 2019

Tried on fresh Laravel installation and works well.

> laravel new 2202
........

> composer require yajra/laravel-datatables-oracle
Using version ^9.7 for yajra/laravel-datatables-oracle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing yajra/laravel-datatables-oracle (v9.7.1): Loading from cache
yajra/laravel-datatables-oracle suggests installing yajra/laravel-datatables-buttons (Plugin for server-side exporting of dataTables.)
yajra/laravel-datatables-oracle suggests installing yajra/laravel-datatables-html (Plugin for server-side HTML builder of dataTables.)
yajra/laravel-datatables-oracle suggests installing yajra/laravel-datatables-fractal (Plugin for server-side response using Fractal.)
yajra/laravel-datatables-oracle suggests installing yajra/laravel-datatables-editor (Plugin to use DataTables Editor (requires a license).)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Discovered Package: yajra/laravel-datatables-oracle
Package manifest generated successfully.

Can anyone provide some steps to replicate this? Thanks!

@mtvbrianking
Copy link
Contributor

Just did a fresh installation and I have the same issue.

Explicitly casting config('datatables.engines') to an array seems to solve it cause its passing null to the foreach.

- $engines = config('datatables.engines');
+ $engines = (array) config('datatables.engines');

@filliph
Copy link

filliph commented Nov 10, 2019

Same issue here, can't run any artisan commands or anything and the entire site has crashed with this error. Being able to replicate the issue shouldn't be necessary to provide a workaround like the one from @mtvbrianking, as this issue is preventing a clean deployment.

Please consider mitigating this issue even if you are unable to replicate it.

@yajra
Copy link
Owner

yajra commented Nov 11, 2019

@filliph of course. The problem is it's hard for me to fix something that I can't replicate. A PR from
the community would be a big help for this.

@mtvbrianking would you mind sending a PR on how you fixed the issue?

@Ayad0net
Copy link

It seems like it is an issue with automatic package discovery in Laravel. If you copy the datatables.php config file into the config directory in Laravel and then run php artisan config:clear it works. Seems like the package discovery is running the boot method before the config file is available to provide the engines array.

Thanks, ^_^

@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants