[英]URL::asset() with php artisan command gives me localhost links
I try to send some emails with a CLI command with php artisan of Laravel, something easy like : 我尝试使用带有php artisan of Laravel的CLI命令发送一些电子邮件,这很简单:
php artisan invitation:send recipient@mail.com
This command is calling a UserController method which contains : 此命令调用UserController方法,该方法包含:
Mail::send('emails.beta.invitation', $data, function($message) use ($address)
{
$message->to($address)
->subject('My subject');
});
The problem is that when it creates the HTML using the view, all references to URL::asset('img/foo.png')
in the template gives me a beautiful : 问题是当它使用视图创建HTML时,模板中对URL::asset('img/foo.png')
所有引用都给了我一个漂亮的:
http://localhost/img/foo.png
instead of the website url : 而不是网站网址:
http://mydomain.com/img/foo.png
If I call this method by calling it in the web browser, there is the good URI for the asset. 如果我通过在Web浏览器中调用此方法来调用此方法,则可以获得资产的良好URI。 I even tried with an environment to the CLI but it doesn't work. 我甚至尝试使用CLI的环境,但它不起作用。 (ie. --env=production
) (即--env=production
)
Where am I wrong ? 我哪里错了?
All right, I got it. 好吧,我明白了。
When using the CLI, Laravel is using the config file app/config/app.php
to read the 'url' (default 'url' => 'http://localhost'
). 使用CLI时,Laravel使用配置文件app/config/app.php
来读取'url'(默认'url' => 'http://localhost'
)。
So I just had to create a new config file under app/config/local/app.php
with : 所以我只需要在app/config/local/app.php
下创建一个新的配置文件:
<?php
return array(
'url' => 'http://localhost:8000',
);
And to change the app/config/app.php
with my production value : 并使用我的生产值更改app/config/app.php
:
'url' => 'http://mydomain.com'
Now it works well ! 现在它运作良好!
https://github.com/laravel/framework/issues/2554#issuecomment-246645265 https://github.com/laravel/framework/issues/2554#issuecomment-246645265
mstephens commented on 13 Sep 2016 Hello mstephens于2016年9月13日评论您好
In App\\Providers\\RouteServiceProvider you can define the following: 在App \\ Providers \\ RouteServiceProvider中,您可以定义以下内容:
/**
* @inheritdoc
*/
public function boot()
{
parent::boot();
/** @var \Illuminate\Routing\UrlGenerator $url */
$url = $this->app['url'];
// Force the application URL
$url->forceRootUrl(config('app.url'));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.