There are links like:
site.ru/page/all - Here is a list of all pages
site.ru/page/1-news-name.html

What is the best way to organize routing for this kind of links?

    1 answer 1

    Documentation for Laravel 5.2 .

    Assumptions in the answer

    A model for your table called Page is assumed.
    Two patterns are assumed:

    • /resources/views/page/all.blade.php
    • /resources/views/page/view.blade.php

    Together with the controller

    routes.php file

     Route::get('/page/all', [ 'as' => 'all', 'uses' => 'YourController@showAll' ]); Route::get('/page/{id}-{slug}.html', [ 'as' => 'page', 'uses' => 'YourController@showPage' ])->where([ // Валидация параметров 'id' => '[0-9]+', 'slug' => '[az-]+' ]); 

    YourController.php file

     <?php namespace App\Http\Controllers; use App\Http\Controllers\Controller; class UserController extends Controller { /** * Список всех страниц * * @return Response */ public function showAll() { return view('page.all', ['pages' => Page::all()]); } /** * Определенная страница * @param int $id * @param string $slug * * @return Response */ public function showPage($id, $slug) { return view('page.view', ['page' => Page::findOrFail($id)]); } } 

    In the showPage() method of the controller, you can search simultaneously by id and slug .
    Do as you like best.

    Without controller

    routes.php file

     Route::get('/page/all', function () { return 'Список всех страниц'; }); Route::get('/page/{id}-{slug}.html', function ($id, $slug) { return "Страница {$id} с ключевым словом {$slug}."; });