如何更改laravel 5.2中的URL默认值?

时间:2017-02-05 05:58:14

标签: php laravel

如何更改Laravel 5.2中的网址(' /')默认值?

我尝试在config / app.php和.env上更改它但仍然无效。

// 'url' => env('APP_URL', 'http://localhost'),
'url' => 'http://localhost',

1 个答案:

答案 0 :(得分:-1)

以下是app.php

的摘录
/*
    |--------------------------------------------------------------------------
    | 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' => env('APP_URL', 'http://localhost'),

这表示此网址仅用于本地工匠任务。

但您尝试将home route重定向到mrvince之类的内容,明确指出当用户到达您的主路线时您将更改网址。

您更改url的目的有所不同,即您总是可能希望将主路由更改为其他内容,但如果您成功更改网址,则无法用于生产目的,因为您不会使用Artisan server中的production

所以,如果需要,我更愿意将请求重定向到其他地方,如:

Route::get('/', function () {
    return redirect()->route('profile');
});

Route::get('profile', [
    'as' => 'profile',
    'uses' => 'SomeController@someMethod'
]);

另请查看此文档:

  

https://laravel.com/docs/5.3/routing#named-routes

希望这会有所帮助。如果我不正确,任何人都可以在这种情况下纠正我。

相关问题