Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the significance of Application URL in laravel 5

Tags:

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

It says Application URL to be used by artisan command line tool , so what should it be actually?

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:

I'll be using laravel schedular from /app/Console/Kernel.php which will be dispatching periodic sendMail commands and that in turn will queue up the mails to be sent in database and queue listner than will process the queue as normal

Queues are working fine at localhost (my local xamp server) however I am concerned as what should be the url value in production

like image 493
echoashu Avatar asked Jun 30 '15 03:06

echoashu


People also ask

What is URL in Laravel?

Laravel allows you to easily create "signed" URLs to named routes. These URLs have a "signature" hash appended to the query string which allows Laravel to verify that the URL has not been modified since it was created.

How do I find base URL in Laravel?

echo base_url(); to get my site's URL.

How can you generate URLs in Laravel?

The action() function can be used as a shortcut to the URL::action() method, and can be used to generate links to controller actions. Just as with the URL::action() method, they can accept second and third parameters for route parameters and secure URL generation.


2 Answers

When a user visits your website, Laravel gets a lot of information it needs about the request from PHP's superglobals ($_SERVER, $_GET, $_POST, etc.). Part of this information is the request URL.

For example, if you access the request methods url() or path(), this information was retrieved via the $_SERVER 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.

like image 180
patricus Avatar answered Oct 14 '22 07:10

patricus


when on production, it should be set to

'url' => 'http://your-live-domain.com', 

As you mentioned, it's going to be used by the artisan commands and queues.

You can leverage .env to store your live domain. http://laravel.com/docs/5.1#environment-configuration

like image 36
Almazik G Avatar answered Oct 14 '22 07:10

Almazik G