Laravel: Get base url

后端 未结 17 1926
梦谈多话
梦谈多话 2020-12-07 10:09

Simple question, but the answer seems quite hard to come by. In Codeigniter, I could load the url helper and then simply do

echo base_url();
<
17条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 10:44

    You can use the URL facade which lets you do calls to the URL generator

    So you can do:

    URL::to('/');
    

    You can also use the application container:

    $app->make('url')->to('/');
    $app['url']->to('/');
    App::make('url')->to('/');
    

    Or inject the UrlGenerator:

    url = $url;
        }
    
        public function methodName()
        {
            $this->url->to('/');
        }
    }
    

提交回复
热议问题