Generating url relative to the base url in laravel 4

后端 未结 2 1910
名媛妹妹
名媛妹妹 2021-02-20 16:42

I\'m new to Laravel & right now building one application on L-4 but got stuck at one place. Can\'t able to understand how to generate url relative to base url. In laravel-3

2条回答
  •  一个人的身影
    2021-02-20 17:41

    First you need to create a Named Route like

    Say yo want to go to http://baseurl/user and runs the method 'showuser' define in controller 'allusers'

    then your Route shold look like this:-

    Route::get('user', array('as' => 'myuser', 'uses' => 'allusers@showuser'));
    

    Now your URL to /user would be

    $myuserurl = URL::to('/myuser');
    echo $myuserurl; // would be http://baseurl/user
    

    I hope this helps you. Pls refer http://laravel.com/docs/routing#named-routes

提交回复
热议问题