| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace HiHaHo\LaravelJsStore; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use HiHaHo\LaravelJsStore\Console\MakeFrontendDataProviderCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Collection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\Facades\Blade; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Illuminate\Support\ServiceProvider as BaseServiceProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | class ServiceProvider extends BaseServiceProvider | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * Bootstrap the application services. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     public function boot() | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |         $this->loadViewsFrom(__DIR__.'/../resources/views', 'js-store'); | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |         Blade::include('js-store::script', 'frontend_store'); | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |         $this->bindDataProviders(); | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |         if ($this->app->runningInConsole()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |             $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |                 __DIR__.'/../config/config.php' => config_path('js-store.php'), | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |             ], 'laravel-js-store-config'); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |             $this->publishes([ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |                 __DIR__.'/../resources/views' => resource_path('views/vendor/js-store'), | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |             ], 'laravel-js-store-views'); | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |             $this->commands([ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |                 MakeFrontendDataProviderCommand::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             ]); | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * Register the application services. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function register() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->mergeConfigFrom(__DIR__.'/../config/config.php', 'js-store'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->app->singleton(Store::class, function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             return new Store; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->app->alias(Store::class, 'js-store'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     protected function bindDataProviders() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $providers = DataProviderCollection::fromConfig('js-store.data-providers'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         if (!$providers->hasData()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         view()->composer('js-store::script', function () use ($providers) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             $providers->store(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 63 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |  | 
            
                        
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: