Reputation: 944
So, in Laravel, there is a web.php file in which class Route is used, and its static functions get and matched are called.
The problem is, that class is a kind of a mistery to me, I can't find it's source in my laravel project, niether can I find anything about it on Internet. If You google it, you'll find Illuminate\Routing\Route but I think that's not the class I'm looking for, because that one doesn't have static functions get and match. I've also tried to look for it my projects directory, and I've found I think four classes with such names, but none of them has these functions which are used in my web.php.
Here is my 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('/', 'BlogController@all')->name('post.all');
Route::match(['get', 'post'], '/article/create', 'BlogController@create')->name('post.create')
->middleware('auth');
Route::get('/article/{id}', 'BlogController@single')->name('post.single');
Route::match(['get', 'post'], '/article/{id}/delete', 'BlogController@delete')->name('post.delete')
->middleware('auth', 'author');
Route::match(['get', 'post'], '/article/{id}/edit', 'BlogController@edit')->name('post.edit')
->middleware('auth', 'author');
Route::get('/author/{id}', 'BlogController@author')->name('post.author');
Route::get('/category/{id}', 'BlogController@category')->name('post.category');
Route::match(['get', 'post'], '/user/create', 'UserController@create')->name('user.create')
->middleware('auth');
Route::get('/home', 'HomeController@index');
Upvotes: 5
Views: 1470
Reputation: 33068
Laravel utilizes some OOP concepts to make your life easier but the flip-side of that as you found out is it also makes it difficult to get "under the hood" and see what's really going on.
A lot of these concepts are explained quite well in the docs but I think the one you are looking at can be found at https://laravel.com/docs/5.3/facades#how-facades-work. I'd also scroll a little further down to the section Facade Class Reference where you will be able to easily see which classes each Facade "points" to. Essentially, it all boils down to the use of the magic method __callStatic()
which allows this magic to happen.
Also in the docs is a sub-heading for "Core Concepts". I'd suggest reading through each of those to get familiar with how the service container works and is utilized and that should give you a better idea of how the facades themselves work.
I'm also going to assume you want to find the class behind the Route
facade to see what other methods there are, in which case you should also look at the project https://github.com/barryvdh/laravel-ide-helper which will give your IDE a better idea of all the methods each facade provides. It can save you a lot of time.
Upvotes: 1
Reputation: 1026
You're almost there;
You'll find it under the Illuminate\Routing\Router
class.
The reason you won't see static functions in here, is because Laravel uses something called "Facades" which provide a static way to access an instantiated class. It essentially wraps the Route class and calls those functions for you.
You can see all facades (including the Route
one) registered to Laravel by looking at config/app.php
under the aliases key.
Upvotes: 3