2016-08-04 42 views
0

我設置項目路徑/config/app.php像爲:如何在Laravel中使用完整路徑控制器?

http://localhost/project/public/ 

所以,當我通過鏈接調用任何控制器點擊:

<a href="/users">Users</a> 

這就要求控制器users

正如你所看到的href是絕對的。

如何設置鏈接,完整路徑項目的各個環節,如爲:

http://localhost/project/public/users 
+0

寫爲答案,這是解決方案,謝謝 – Dev

+0

@Putin有你甚至不屑於閱讀文檔?你有關於Laravel開放的一些非常基本的問題。問題非常簡單,文檔涵蓋了所有**的文檔... –

回答

3

使用Laravel的助手此。

https://laravel.com/docs/5.2/helpers

urlrouteaction助手都這麼做(方式略有不同)。

<a href="{{ url('users') }}">Users</a> 

側面說明:您非公開的文件夾不應該暴露在生產公共互聯網。您的網絡服務器應指向public文件夾作爲其文檔根目錄。

1

最好的做法是使用命名路由,該路由將動態工作,不像url('path')那裏你必須在任何地方手動改變路徑。

Route::get('user/profile', [ 
    'as' => 'profile', 'uses' => '[email protected]' 
]); 

,您可以訪問這個輔助方法

route('profile')

這也適用於動態路由的作品像

Route::get('profile/{id}', [ 
    'as' => 'profile', 'uses' => '[email protected]' 
]); 

$id或數組作爲第二個參數的完整路徑。

route('profile', $id) 

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

相關問題