in Config/app.php in laravel source, what is the actual use of url ?

上面说应用程序URL将被artisan command line tool使用,那么它应该是什么呢?

I mean should it be http://mydomainname.com or should it be /var/www/laravel/ or /var/www/laravel/public

Current Configuration

/*
|--------------------------------------------------------------------------
| 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://localhost/',

Provided my application source is located at /var/www/ directory and laravel public folder is /var/www/laravel/public And the http://mydomainname.com is pointed to resolve at /var/www/laravel/public directory

Use Case:

我将使用/app/Console/Kernel.php中的laravel schedular,它将调度periodic sendMail commands,然后将在数据库中对要发送的邮件进行排队,而queue listner将照常处理队列

在localhost(我的本地xamp服务器)上,队列工作正常,但我担心生产中的url%值应该是多少

推荐答案

当用户访问您的网站时,Laravel会从PHP的superglobals($_服务器,$_GET,$_POST,等等)获取大量有关请求的信息.此信息的一部分是请求URL.

例如,如果访问请求方法url()path(),则通过$_服务器superglobal检索此信息:

$url = Request::url();
$path = Request::path();

However, artisan, commands, jobs, etc. don't have the benefit of this information. It is not a normal HTTP request coming in from the user, it is a PHP command being run from the command line. Because of this, Laravel needs a way to determine what the url of the application should be. This is where the configuration value comes in.

In your example, you plan on sending out emails from a queue. Imagine you need to include a link to a route of your website in one of the emails, so you use the UrlGenerator to get the url for the link (URL::route('route.name')). Since this code is being run inside a command, and isn't related to any type of HTTP request, the base application url will be picked up from the configuration value you set in config/app.php.

As should hopefully be a little more clear now, the url value should be set to the http url for your application, not any type of directory path. In your example, it should be http://mydomainname.com.

Laravel相关问答推荐

如何为 CMP 横幅安装谷歌同意脚本?

使用枢轴插入多对多时的Laravel问题

Laravel 如何处理来自浏览器的 PUT 请求?

Eloquent: hasNot 带参数

Laravel 保存一对多关系

如何在 NetBeans 中添加带有点 (blade.php) 的自定义文件扩展名?

链接到容器时如何使用主机网络?

如何从 laravel 控制器执行外部 shell 命令?

Laravel Artisan Scheduler 中的链式命令?

在 laravel 分页中添加一些数据

如何在本地 Laravel Homestead 站点上获取 https 证书

约定表名(带下划线)

在 Laravel 5.4 中向多个抄送收件人发送Electron邮件

反向代理后面的 Laravel 路由

Laravel 5 Carbon 全局语言环境

Carbon解析到 ISO8601

Lumen/Laravel 6:调用未定义的函数 array_except()

Laravel 用户能力

count() 参数必须是数组或在 laravel 中实现可数的对象

限制自己重载外部 API 的速率