我運行一個內置在Laravel 4.2中的多租戶網站。在App配置中,我知道您可以設置單個基本網址,例如更改Laravel 4.2內部的應用程序URL Artisan命令
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/
'url' => 'http://apples.local',
我已經建立了一個工匠命令提供定期寄送電子郵件給用戶,無論他們通過訪問該網站的域。因此,該命令需要生成具有不同域的URL,例如http://oranges.local
。
在我的命令,我試圖生成的URL之前改變app.url
配置變量,但似乎沒有影響:
Config::set('app.url', 'http://oranges.local');
$this->info('App URL: ' . Config::get('app.url'));
$this->info('Generated:' . URL::route('someRoute', ['foo', 'bar']));
儘管在運行時實際改變配置,這還總是產生:
App URL: http://oranges.local
Generated: http://apples.local/foo/bar
URL生成器完全忽略了應用程序配置!
我知道我可以設置多個環境並將--env=oranges
傳遞給Artisan,但在我的使用案例中,這並不實際。我只想在運行時在站點範圍內設置應用程序url。
任何想法?
從URL生成器(而不是絕對路徑)獲取路由路徑並單獨追加域是否可行?例如,'URL :: route('someRoute',['foo','bar'],false);''會產生'/ foo/bar'。 – benJ
謝謝,是的,我也曾考慮過這個問題,但問題仍然是我的用例。您的建議適用於我自己生成的網址,但我也使用生成自己的網址的套餐,例如。 https://github.com/iwyg/jitimage,這些也需要渲染正確的域名,而不僅僅是默認的根網址。 – Andrew