Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 invitation:send [email protected]

This command is calling a UserController method which contains :

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 :

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. I even tried with an environment to the CLI but it doesn't work. (ie. --env=production)

Where am I wrong ?

like image 830
grena Avatar asked Sep 22 '13 18:09

grena


People also ask

What does php artisan command do?

The Laravel PHP artisan serve command helps running applications on the PHP development server. As a developer, you can use Laravel artisan serve to develop and test various functions within the application. It also accepts two additional options. You can use the host for changing application's address and port.

What is difference between URL and asset in laravel?

{{url}} allows you to create a link to a URL on your site -- another benefit is the fact that you can set the second parameter to an array with query string parameters within. {{asset} simply allows you to link to an asset within your public directory -- for example css/main.


1 Answers

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').

So I just had to create a new config file under app/config/local/app.php with :

<?php
return array(
    'url' => 'http://localhost:8000',
);

And to change the app/config/app.php with my production value :

'url' => 'http://mydomain.com'

Now it works well !

like image 129
grena Avatar answered Sep 28 '22 02:09

grena