The vendor:publish
command is used to publish any assets that are available from third-party vendor packages. It provides a few options to help specifically choose which assets should be published. The following table lists and describes each of the options that are available for use:
Option | Description |
---|---|
--force |
Supplying this flag will cause the vendor:publish command to overwrite any existing files. |
--provider=<PROVIDER> |
Supplying a value for <PROVIDER> will cause the command to only publish the assets associated with the specified service provider. |
--tag=* |
A list of tags to limit the types of assets that will be published. |
The following service provider will be used to demonstrate the usage of the vendor:publish
command:
1<?php
2
3namespace App\Providers;
4
5use Illuminate\Support\ServiceProvider;
6
7class ExampleServiceProvider extends ServiceProvider
8{
9 /**
10 * Bootstrap the application services.
11 *
12 * @return void
13 */
14 public function boot()
15 {
16
17 // Translations example.
18 // `translations` is the tag.
19 $this->publishes([
20 __DIR__.'/example/translations' =>
21 resource_path('lang/vendor/example')
22 ], 'translations');
23
24 // Migrations example.
25 $this->publishes([
26 __DIR__.'/example/migrations' => database_path('migrations')
27 ], 'migrations');
28
29 // Configuration example.
30 // `config` is the tag.
31 $this->publishes([
32 __DIR__.'config/example.php' => config_path('example.php')
33 ], 'config');
34
35 // Public assets example.
36 // `public` is the tag.
37 $this->publishes([
38 __DIR__.'example/assets' => public_path('vendor/example')
39 ], 'public');
40 }
41
42 /**
43 * Register the application services.
44 *
45 * @return void
46 */
47 public function register()
48 {
49 //
50 }
51}
The following command would simply attempt to publish the assets from all registered providers. The defaults will be used; no existing files will be overwritten and all tags will be publishes.
1# Publish all vendor assets.
2php artisan vendor:publish
The following would only publish the assets for the App\Providers\ExampleServiceProvider
service provider:
1# Publish only the ExampleServiceProvider assets.
2php artisan vendor:publish --provider="App\Providers\ExampleServiceProvider"
The following examples demonstrate different uses of the vendor:publish
command:
1# Force files to be overwritten if they exist.
2php artisan vendor:publish --force
3
4# Publish assets that have the specified tags.
5php artisan vendor:publish --tag=public --tag=migrations
∎