patterns() public static method

Set a group of global where patterns on all routes.
public static patterns ( array $patterns ) : void
$patterns array
return void
Example #1
0
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function () {
    /*
       注意:你的默认的数据库连接
       oauth
    */
    return 'laravel 4 app';
    return View::make('index');
});
Route::get('test', 'TestController@test');
Route::patterns(['id' => '[1-9][0-9]*', 'comment_id' => '[1-9][0-9]*']);
Route::group(array('prefix' => 'v3'), function () {
    Route::get('journals', 'JournalController@index');
    Route::get('journals/{id}', 'JournalController@show');
    Route::put('journals/{id}/stars', 'JournalController@star');
    Route::delete('journals/{id}/stars', 'JournalController@unstar');
    Route::post('users', 'UserController@store');
    Route::post('oauth/access_token', 'OAuthController@postAccessToken');
    Route::delete('oauth/invalidate_token', 'UserController@logout');
    Route::get('journals/{id}/comments', 'JournalController@commentList');
    // 用户期刊评论
    Route::post('journals/{id}/comments', 'JournalController@comment');
    // 匿名用户期刊评论
    Route::post('journals/{id}/anonymous_comments', 'JournalController@anonymousComment');
    Route::put('journals/{id}/comments/{comment_id}/favours', 'CommentController@favour');
    Route::delete('journals/{id}/comments/{comment_id}/favours', 'CommentController@unfavour');
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::patterns(['categoryId' => '[0-9]+', 'albumId' => '[0-9]+', 'imageId' => '[0-9]+', 'userId' => '[0-9]+']);
// Categories
Route::group(['before' => 'authForRole:' . User::RESTRICTED], function () {
    Route::get('/', function () {
        return Redirect::to('/categories');
    });
    Route::get('/categories', 'CategoryController@index');
    Route::get('/categories/create', 'CategoryController@create');
    Route::post('/categories/create', 'CategoryController@create');
});
Route::group(['before' => 'authForRole:' . User::NORMAL], function () {
    Route::get('/categories/{categoryId}/update', 'CategoryController@update');
    Route::post('/categories/{categoryId}/update', 'CategoryController@update');
    Route::get('/categories/{categoryId}/delete', 'CategoryController@delete');
    Route::post('/categories/{categoryId}/delete', ['before' => 'csrf', 'uses' => 'CategoryController@delete']);
});
// Albums
Route::group(['before' => 'authForRole:' . User::RESTRICTED], function () {
    Route::get('/categories/{categoryId}/albums', 'AlbumController@index');
    Route::get('tag/{tag}', ['as' => 'show.tag.products', 'uses' => 'StoreController@tagProducts']);
    Route::group(['prefix' => 'cart'], function () {
        Route::get('/', ['as' => 'cart', 'uses' => 'CartController@index']);
        Route::get('/add/{id}', ['as' => 'cart.add', 'uses' => 'CartController@add']);
        Route::get('/remove/{id}', ['as' => 'cart.remove', 'uses' => 'CartController@remove']);
        Route::get('/destroy/{id}', ['as' => 'cart.destroy', 'uses' => 'CartController@destroy']);
    });
    Route::group(['middleware' => 'auth'], function () {
        Route::get('checkout/order-place', ['as' => 'checkout.orderPlace', 'uses' => 'CheckoutController@place', 'middleware' => 'exists_address']);
        Route::get('account/orders/', ['as' => 'account.orders', 'uses' => 'AccountController@orders']);
        Route::get('account/address/create/{redirect_to?}', ['as' => 'account.address', 'uses' => 'AccountController@createAddress']);
        Route::post('account/address/save', ['as' => 'account.address.save', 'uses' => 'AccountController@saveAddress']);
        Route::get('account', ['as' => 'account', 'uses' => 'AccountController@index']);
    });
});
Route::patterns(['category' => '[0-9]+', 'product' => '[0-9]+']);
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'is_admin']], function () {
    Route::group(['prefix' => 'categories'], function () {
        Route::get('/', ['as' => 'categories.index', 'uses' => 'AdminCategoriesController@index']);
        Route::get('create', ['as' => 'categories.create', 'uses' => 'AdminCategoriesController@create']);
        Route::post('store', ['as' => 'categories.store', 'uses' => 'AdminCategoriesController@store']);
        Route::get('edit/{category}', ['as' => 'categories.edit', 'uses' => 'AdminCategoriesController@edit']);
        Route::put('update/{category}', ['as' => 'categories.update', 'uses' => 'AdminCategoriesController@update']);
        Route::get('destroy/{category}', ['as' => 'categories.destroy', 'uses' => 'AdminCategoriesController@destroy']);
    });
    Route::group(['prefix' => 'products'], function () {
        Route::get('/', ['as' => 'products.index', 'uses' => 'AdminProductsController@index']);
        Route::get('create', ['as' => 'products.create', 'uses' => 'AdminProductsController@create']);
        Route::post('store', ['as' => 'products.store', 'uses' => 'AdminProductsController@store']);
        Route::get('edit/{product}', ['as' => 'products.edit', 'uses' => 'AdminProductsController@edit']);
        Route::put('update/{product}', ['as' => 'products.update', 'uses' => 'AdminProductsController@update']);
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
// List of patterns for route parameters
Route::patterns(['ARTICLE' => '^([a-z0-9]+(?:[_-]?[a-z0-9]+)*(?:\\/[a-z0-9]+(?:[_-]?[a-z0-9]+)*)*)(?:-{2}([A-Za-z0-9_]+))?$']);
// Default controllers
Route::controllers(['auth' => Auth\AuthController::class, 'password' => Auth\PasswordController::class]);
// Pages URL
Route::get('/', ['as' => 'home', 'uses' => 'HomeController@index']);
// Test URL
Route::get('test/{page}', ['as' => 'test', 'uses' => function ($page) {
    switch ($page) {
        case 'admin':
            return view('_testview/admin_index');
        case 'home':
            return view('_testview/home_index');
        default:
            return 'This URL is only for testing!';
    }
}]);
// Controllers within the "App\Http\Controllers\Admin" namespace
// Route name: admin::@dmin-zone...
<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::get('/', function () {
    exit('backend');
    // return View::make('hello');
});
Route::patterns(['id' => '[1-9][0-9]*', 'comment_id' => '[1-9][0-9]*', 'type' => 'weibo|qq|weixin']);
Route::group(array('prefix' => 'v1'), function () {
    // todo
});