Member-only story
Do you know about Laravel vendor publish?
Laravel vendor publish allow you to select which vendor config, public assets or resources file to publish
The vendor:publish
command in Laravel did not have a built-in search functionality on the prompt. This means that when you run php artisan vendor:publish
, it lists all available package providers, and you need to select the provider you want to publish files for manually by typing its number.
However, you can implement a custom solution to add search functionality to the vendor:publish
prompt by extending the VendorPublishCommand
class provided by Laravel. Here's a high-level overview of how you can do it:
- Create a new command class that extends the
VendorPublishCommand
class:
php artisan make:command CustomVendorPublish
2. In your CustomVendorPublish
command class, override the getAvailableProviders
method to filter the available providers based on the user's search input:
protected function getAvailableProviders()
{
$providers = parent::getAvailableProviders();
$searchTerm = $this->ask('Enter a search term to filter providers:');
if (!empty($searchTerm)) {
$providers = array_filter($providers, function ($provider) use ($searchTerm) {
return str_contains($provider, $searchTerm);
});
}…