Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'd like to know about class Route used in web.php

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');
like image 725
Scarass Avatar asked Dec 28 '16 16:12

Scarass


People also ask

What are routes in php?

The routes/web.php file defines routes that are for your web interface. These routes are assigned the web middleware group, which provides features like session state and CSRF protection. The routes in routes/api.php are stateless and are assigned the api middleware group.

Why we use routes in Laravel?

Routing in Laravel allows users to route all their application demands to its appropriate controller. The most primary routes in Laravel acknowledge and accept a Uniform Asset Identifier together with a closure, given that it should be got to be a simple and expressive way of routing.


1 Answers

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.

like image 141
SixteenStudio Avatar answered Oct 06 '22 00:10

SixteenStudio