Artisan 的tinker 命令是在終端機中修改應用程式的好方法。不幸的是,運行幾行程式碼、進行編輯以及複製/貼上程式碼可能會很麻煩。在瀏覽器中進行修改不是很好嗎?
該軟體包將為您的應用程式添加一條路線,您可以在其中隨意修改。
如果光線傷害你的眼睛,還有黑暗模式。
我們投入了大量資源來創建一流的開源套件。您可以透過購買我們的一款付費產品來支持我們。
我們非常感謝您從家鄉寄給我們一張明信片,並註明您正在使用我們的哪種套餐。您可以在我們的聯絡頁面上找到我們的地址。我們在虛擬明信片牆上發布所有收到的明信片。
該包可以運行任意代碼。除非您知道自己在做什麼,否則切勿在生產環境或處理真實世界數據的任何環境中安裝或使用它。
您可以透過 Composer 安裝該軟體包:
composer require spatie/laravel-web-tinker --dev
接下來,您必須透過執行此命令來發布此套件中的資產。
php artisan web-tinker:install
或者,您可以發布套件的設定檔。
php artisan vendor:publish --provider= " SpatieWebTinkerWebTinkerServiceProvider " --tag= " config "
這是將發佈到config/web-tinker.php
的內容
return [
/*
* The web tinker page will be available on this path.
*/
' path ' => ' /tinker ' ,
/*
* Possible values are 'auto', 'light' and 'dark'.
*/
' theme ' => ' auto ' ,
/*
* By default this package will only run in local development.
* Do not change this, unless you know what your are doing.
*/
' enabled ' => env ( ' APP_ENV ' ) === ' local ' ,
/*
* This class can modify the output returned by Tinker. You can replace this with
* any class that implements SpatieWebTinkerOutputModifiersOutputModifier.
*/
' output_modifier ' => Spatie WebTinker OutputModifiers PrefixDateTime::class,
/*
* These middleware will be assigned to every WebTinker route, giving you the chance
* to add your own middlewares to this list or change any of the existing middleware.
*/
' middleware ' => [
Illuminate Cookie Middleware EncryptCookies::class,
Illuminate Session Middleware StartSession::class,
Spatie WebTinker Http Middleware Authorize::class,
],
/*
* If you want to fine-tune PsySH configuration specify
* configuration file name, relative to the root of your
* application directory.
*/
' config_file ' => env ( ' PSYSH_CONFIG ' , null ),
];
預設情況下,此套件僅在本機環境中運作。
在應用程式的本機環境中造訪/tinker
以查看修補程式頁面。
如果您想在其他環境中執行此程式(我們不建議這樣做),則必須執行兩個步驟。
viewWebTinker
功能。執行此操作的一個好地方是 Laravel 附帶的AuthServiceProvider
。 public function boot ()
{
$ this -> registerPolicies ();
Gate:: define ( ' viewWebTinker ' , function ( $ user = null ) {
// return true if access to web tinker is allowed
});
}
web-tinker
設定檔中的enabled
變數設為true
。 您可以透過在web-tinker
設定檔的output_modifier
鍵中指定輸出修飾符來修改tinker 的輸出。輸出修飾符是任何實作SpatieWebTinkerOutputModifiersOutputModifier
的類別。
這就是該介面的樣子。
namespace Spatie WebTinker OutputModifiers ;
interface OutputModifier
{
public function modify ( string $ output = '' ): string ;
}
該軟體包的預設安裝將使用PrefixDataTime
輸出修飾符,該修飾符在 Tinker 的輸出中添加當前日期時間的前綴。
composer test
請參閱變更日誌以了解有關最近更改內容的更多資訊。
詳細資訊請參閱貢獻。
如果您發現有關安全的錯誤,請發送郵件至 [email protected],而不是使用問題追蹤器。
該軟體包的靈感來自於 Marcel Pociot 的 nova-tinker-tool 軟體包,並使用了其中的程式碼。
麻省理工學院許可證 (MIT)。請參閱許可證文件以獲取更多資訊。