【问题标题】:Laravel route() - not passing root folder nameLaravel route() - 不传递根文件夹名称
【发布时间】:2020-12-31 21:47:00
【问题描述】:

提前谢谢你,

我定义了一条路线

Route::get('/registration/verify/{token}', 'UserController@verifyRegisteredEmail')->name('registration.email.verification');

我正在访问类似的路线

route('registration.email.verification', ['token' => $email_register_verification_token]);

当我在上面打印时,它如下所示

http://localhost/registration/verify/87006dcc95bcf7a9ea83e523f2aa53f9

但应该是的

http://localhost/{root}/registration/verify/87006dcc95bcf7a9ea83e523f2aa53f9

【问题讨论】:

  • 你试试APP_URL=http:://.sitename
  • APP_URL=http:://domain.com 可以解决这个问题,您还有一个问题:Yes this worked, but when i am passing the same things in href of an anchor tag, it is not required to set APP_URL,因为在您的浏览器上,您的href 将您当前的域设置为根 url。假设您当前的域是 2 domain.com/hello/index.php,而您的 href/style.css,那么您的浏览器将调用 domain.com/style.css。如果您的hrefstyle.css,那么它将调用domain.com/hello/style.css
  • Yupp 明白了你的意思,非常感谢@sta

标签: laravel laravel-routing


【解决方案1】:

尝试在 .env 文件中设置APP_URL,并运行此命令php artisan config:cache

【讨论】:

    【解决方案2】:

    如果您有一些具有相同前缀的路由,您可以在路由组中使用前缀选项,如下所示:

    Route::prefix('Your Root')->group(function(){
    Route::get('/registration/verify/{token}', 'UserController@verifyRegisteredEmail')->name('registration.email.verification');
    
    });
    
    

    【讨论】:

      【解决方案3】:

      尝试在.env 中设置正确的APP_URL。它只会从那里输出错误的值。

      【讨论】:

      • 是的,这行得通,但是当我在锚标签的 href 中传递相同的东西时,不需要设置 APP_URL
      猜你喜欢
      • 1970-01-01
      • 2021-06-21
      • 1970-01-01
      • 1970-01-01
      • 2020-12-06
      • 2019-12-02
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多