2016-12-28 53 views
1

所以,在Laravel,有在使用類路由一個web.php文件,它的靜態函數獲取和匹配稱爲類路徑。我想了解一下web.php使用

的問題是,這個類是怎樣的一個謎給我的,我無法找到它在我的laravel項目源,niether可以找到關於它的任何互聯網。 如果你谷歌它,你會發現Illuminate \ Routing \ Route,但我認爲這不是我正在尋找的類,因爲那個沒有靜態函數獲取和匹配。 我也試過尋找它,我的項目目錄,我發現我認爲這樣的名稱的四個類,但他們都沒有這些功能,這是在我的web.php中使用。

這裏是我的web.php:

<?php 

/* 
|-------------------------------------------------------------------------- 
| Web Routes 
|-------------------------------------------------------------------------- 
| 
| Here is where you can register web routes for your application. These 
| routes are loaded by the RouteServiceProvider within a group which 
| contains the "web" middleware group. Now create something great! 
| 
*/ 

Route::get('/', function() { 
    return view('welcome'); 
}); 

Auth::routes(); 

Route::get('/', '[email protected]')->name('post.all'); 

Route::match(['get', 'post'], '/article/create', '[email protected]')->name('post.create') 
    ->middleware('auth'); 

Route::get('/article/{id}', '[email protected]')->name('post.single'); 

Route::match(['get', 'post'], '/article/{id}/delete', '[email protected]')->name('post.delete') 
    ->middleware('auth', 'author'); 

Route::match(['get', 'post'], '/article/{id}/edit', '[email protected]')->name('post.edit') 
    ->middleware('auth', 'author'); 

Route::get('/author/{id}', '[email protected]')->name('post.author'); 

Route::get('/category/{id}', '[email protected]')->name('post.category'); 

Route::match(['get', 'post'], '/user/create', '[email protected]')->name('user.create') 
    ->middleware('auth'); 

Route::get('/home', '[email protected]'); 

回答

1

你幾乎沒有;

你會發現它的Illuminate\Routing\Router類下。

,你不會看到在這裏靜態函數究其原因,是因爲Laravel使用一種叫「門面」,它提供了訪問實例化類的靜態方法。它基本上包裝了Route類併爲你調用了這些函數。

通過在別名鍵下查看config/app.php,您可以看到註冊到Laravel的所有正面(包括Route一個正面)。

1

你要找的​​類

1

Laravel使用一些OOP的概念,使您的生活更輕鬆,但的,當你發現了翻蓋側是它也很難得到「引擎蓋下」和看看到底發生了什麼。

很多這些概念在文檔中解釋得很好,但我認爲你是在尋找可以在https://laravel.com/docs/5.3/facades#how-facades-work中發現的一個。我還會進一步向下滾動到Facade Class Reference部分,您可以輕鬆查看每個Facade「指向」哪些類。從本質上講,這一切歸結爲使用神奇的方法__callStatic(),它允許這種魔法發生。

另外,在文檔是「核心概念」的分標題。我建議通過閱讀每個人來熟悉服務容器的工作方式和使用方法,這應該讓您更好地瞭解外牆自身的工作原理。

我也將假設你想要找的Route門面背後的類,看看有什麼其他的方法還有,在這種情況下,你也應該看項目https://github.com/barryvdh/laravel-ide-helper這將給你的IDE都更好的主意每個門面提供的方法。它可以爲你節省很多時間。