6

Normally laravel will detect the base url automatically. However, this is not possible when the function is called by command line in console. Therefore, under path_to_laravel_folder/public/config/app.php, there is a variable named url, which according to the official comment, should be the base url when laravel is called in command line.

Currently I have a daily task to be run on laravel and therefore is called by command line. In the app.php, I have set the url variable to be:

'url' => 'http://localhost/laravel/public/',

However, when I check the output of my daily job, the base url is always

http://localhost/

Is this a bug or the sub-directory should be set else where?


P.S.

As suggested in the comment session, I am adding some details on what function I called for base url.

Actually, I am writing a daily job to send email to remind the user to do something on my site. It will first read from database on which user wants a reminder and sends a email if this user is found in our database. The function that need the base url is in the view file of the email, namely path_to_laravel/public/view/email/reminder.blade.php The code looks like this:

<!-- some other email content-->
... <a href="{{ url('/controllerName/method/'.$user_id) }}"> click here to go to the site </a> ....
<!-- some other email content -->

The $user_id is set in command file. The link will redirect to login page is user is not login yet.

cytsunny
  • 4,838
  • 15
  • 62
  • 129
  • Are you sure that you are not in local environment? If so, you should edit `config/local/app.php`. – Hkan Nov 24 '14 at 11:21
  • On the contrary, I am quite sure I am in local environment and actually set that in path_to_laravel_folder/public/config/local/app.php. I didn't mention that because it is not relevant to the problem. Also, I have tried to change the url to http://localhost.com/laravel/public, it turns out that it reacts and changed to http://localhost.com/, but still omitting the directory. – cytsunny Nov 24 '14 at 11:34
  • Could you also post the code that seems to be using `app.url` config wrongly? – Hkan Nov 24 '14 at 18:31
  • I have just added the details in my question. – cytsunny Nov 25 '14 at 06:13
  • What does `url()` without any parameters output? And also can you try without the leading slash that example you've provided? – Hkan Nov 25 '14 at 09:58
  • url() is the function provided by laravel..... http://laravel.com/docs/4.2/helpers#urls It outputs a qualified URL, which in other words put the base url at the front. I have tried removing the slash in front but it still doesn't work. – cytsunny Nov 26 '14 at 01:41

0 Answers0