Laravel: Get base url

后端 未结 17 1766
梦谈多话
梦谈多话 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:29

    By the way, if your route has a name like:

    Route::match(['get', 'post'], 'specialWay/edit', 'SpecialwayController@edit')->name('admin.spway.edit');
    

    You can use the route() function like this:

    <form method="post" action="{{route('admin.spway.edit')}}" class="form form-horizontal" id="form-spway-edit">
    

    Other useful functions:

    $uri = $request->path();
    $url = $request->url();
    $url = $request->fullUrl();
    asset()
    app_path();
    // ...
    

    https://github.com/laravel/framework/blob/5.4/src/Illuminate/Foundation/helpers.php

    0 讨论(0)
  • 2020-12-07 10:30

    Laravel < 5.2

    echo url();
    

    Laravel >= 5.2

    echo url('/');
    

    Hope this helps you

    0 讨论(0)
  • 2020-12-07 10:30

    Check this -

    <a href="{{url('/abc/xyz')}}">Go</a>
    

    This is working for me and I hope it will work for you.

    0 讨论(0)
  • 2020-12-07 10:36

    I also used the base_path() function and it worked for me.

    0 讨论(0)
  • 2020-12-07 10:41

    To get it to work with non-pretty URLs I had to do:

    asset('/');
    
    0 讨论(0)
  • 2020-12-07 10:42

    I used this and it worked for me in Laravel 5.3.18:

    <?php echo URL::to('resources/assets/css/yourcssfile.css') ?>
    

    IMPORTANT NOTE: This will only work when you have already removed "public" from your URL. To do this, you may check out this helpful tutorial.

    0 讨论(0)
提交回复
热议问题