Skip to content

Instantly share code, notes, and snippets.

@rc1021
Last active February 19, 2017 08:46
Show Gist options
  • Select an option

  • Save rc1021/3120c19e4c956b79108efbc20ab0ecca to your computer and use it in GitHub Desktop.

Select an option

Save rc1021/3120c19e4c956b79108efbc20ab0ecca to your computer and use it in GitHub Desktop.
using vendor:publish on packages not in vendor

背景

當我在開發 Laravel package 並使用 php artisan vendor:publish --provider=VendorName\Space\TasksServiceProvider 會發生以下狀況:

Nothing to publish for tag [].

後來問谷歌之後,才發現只是忘了加雙引號 :|

(04.24更新)另外,在Laravel 台灣(臉書社團)的陳彥齊也說有另一個原因

在 bash 環境,反斜線是跳脫字元
對 bash 而言 VendorName\Space\TasksServiceProvider 他會看做是 VendorNameSpaceTasksServiceProvider
但雙引號內不跳脫
echo "\\" 是 \\
echo \\ 是 \

以下是正解:

# correct 1
php artisan vendor:publish --provider="VendorName\Space\TasksServiceProvider"

# correct 2
php artisan vendor:publish --provider=VendorName\\Space\\TasksServiceProvider

# wrong!
php artisan vendor:publish --provider=VendorName\Space\TasksServiceProvider

歡迎加入我的 LINE ID: easter1021

<?php
namespace VendorName\Space;
use Illuminate\Support\ServiceProvider;
class TasksServiceProvider extends ServiceProvider
{
public function boot()
{
$this->publishes([
__DIR__.'/config/vendor_name_space.php' => config_path('vendor_name_space.php')
], 'config');
$this->publishes([
__DIR__ . '/migrations/' => base_path('/database/migrations')
], 'migrations');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment