{"id":9381,"date":"2024-01-24T04:59:28","date_gmt":"2024-01-24T04:59:28","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=9381"},"modified":"2024-01-24T05:00:26","modified_gmt":"2024-01-24T05:00:26","slug":"disable-providers-from-package-discovery","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/laravel\/disable-providers-from-package-discovery","title":{"rendered":"How to Disable Providers From Package Discovery?"},"content":{"rendered":"<p><strong>Auto Discovery<\/strong> was introduced in Laravel 5.5. Auto-discovery feature allows to automatically register package service providers and services which eliminates manual configuration needs.<\/p>\n<p>It helps to speed up the package installation process and reduces any possible human errors. But sometimes, there are situations where we need to have more control over what needs to be loaded and when.<\/p>\n<p>In such cases, we can use the Disabling <strong>Auto Discovery<\/strong> feature of laravel. By Disabling Auto Discovery in Laravel, we can explicitly control which service providers are loaded for your application and also decide in what order they need to be loaded.<\/p>\n<p>Before Auto Discovery, we had to manually register the service providers and facades in the config\/app.php file. However, with Auto Discovery, Laravel automatically detects and registers them.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">\/\/ Before Auto Discovery, you had to manually add service providers and facades\r\n'providers' =&gt; [\r\n    \/\/ Other Service Providers...\r\n\r\n    \/\/ Manually added Service Provider\r\n    Package\\ServiceProvider::class,\r\n],\r\n\r\n'aliases' =&gt; [\r\n    \/\/ Other Facades...\r\n\r\n    \/\/ Manually added Facade\r\n    'PackageFacade' =&gt; Package\\Facade::class,\r\n],\r\n<\/pre>\n<h2>How to Disable Auto Discovery in Laravel<\/h2>\n<p>Lets learn step-by-step, how to disable auto discovery in laravel:<\/p>\n<h3>Step-1<\/h3>\n<p>Open your <strong>composer.json<\/strong> file located in the root directory of your Laravel application.<\/p>\n<h3>Step-2<\/h3>\n<p>In the composer.json file, you can add the dont-discover option in the extra section. This option allows you to specify the packages for which you want to disable Auto Discovery.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">\r\n\"extra\": {\r\n    \"laravel\": {\r\n        \"dont-discover\": [\r\n            \"Vendor\/PackageName\"\r\n        ]\r\n    }\r\n}\r\n<\/pre>\n<p>In the above code, replace &#8220;Vendor\/PackageName&#8221; with the name of the package for which you want to disable Auto Discovery.<\/p>\n<h3>Step-3<\/h3>\n<p>If you want to disable Auto-Discovery for all packages, you can use the * wildcard.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">\r\n\"extra\": {\r\n    \"laravel\": {\r\n        \"dont-discover\": [\r\n            \"*\"\r\n        ]\r\n    }\r\n}\r\n<\/pre>\n<h3>Step-4<\/h3>\n<p>After making changes to your composer.json file, you need to update your dependencies. You can do this by running the composer update command in your terminal.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">composer update<\/pre>\n<h2>Issues Related to Disabling Auto Discovery<\/h2>\n<p>Disabling auto-discovery of packages often raises issues over providing control to the application. Here are the few issues related to disabling auto-discovery of packages in laravel:<\/p>\n<h3>1. Package Not Found<\/h3>\n<p>This is the most common error related to disabling auto discovery. This error occurs when Laravel tries to use a package that hasn\u2019t been manually registered.<\/p>\n<p><strong>Solution:<\/strong> Ensure that you have manually registered all the necessary service providers and facades in  config\/app.php file for the packages listed in the dont-discover array.<\/p>\n<h3>2. Incorrect order of service providers<\/h3>\n<p>Another issue could be the incorrect order of service providers. The order in which service providers are loaded can affect how your application works.<\/p>\n<p><strong>Solution:<\/strong> Ensure that you have arranged the service providers in the correct order in the <strong>app.php<\/strong> file.<\/p>\n<h3>3. Performance Issues<\/h3>\n<p>Disabling Auto Discovery might also lead to performance issues if not done correctly. This is because Laravel would not be able to optimize the loading of service providers and facades.<\/p>\n<p><strong>Solution:<\/strong> If you are facing performance issues, consider enabling Auto Discovery for some of the packages.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Auto Discovery was introduced in Laravel 5.5. Auto-discovery feature allows to automatically register package service providers and services which eliminates manual configuration needs. It helps to speed up the package installation process and reduces any possible human errors. But sometimes, there are situations where we need to have more control over what needs to be [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9382,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[10],"tags":[],"class_list":["post-9381","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9381"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=9381"}],"version-history":[{"count":3,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9381\/revisions"}],"predecessor-version":[{"id":9385,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9381\/revisions\/9385"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/9382"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=9381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=9381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=9381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}