title: Difference between middleware route group and namespaces route group in laravel 5.1?
body: <p>I was reading laravel 5.1 documentation. I didn't understand how laravel route group working and what's the difference between following route groups.</p>
  
  <p><strong>Route Groups &amp; Named Routes</strong></p>
  
  <p>If you are using route groups, you may specify an as keyword in the route group attribute array, allowing you to set a common route name prefix for all routes within the group:</p>
  
  <pre><code>Route::group(['as' =&gt; 'admin::'], function () {
      Route::get('dashboard', ['as' =&gt; 'dashboard', function () {
          // Route named "admin::dashboard"
      }]);
  });
  </code></pre>
  
  <p><strong>Middleware</strong></p>
  
  <p>To assign middleware to all routes within a group, you may use the middleware key in the group attribute array. Middleware will be executed in the order you define this array:</p>
  
  <pre><code>Route::group(['middleware' =&gt; 'auth'], function () {
      Route::get('/', function ()    {
          // Uses Auth Middleware
      });
  
      Route::get('user/profile', function () {
          // Uses Auth Middleware
      });
  });
  </code></pre>
  
  <p><strong>Namespaces</strong></p>
  
  <p>Another common use-case for route groups is assigning the same PHP namespace to a group of controllers. You may use the namespace parameter in your group attribute array to specify the namespace for all controllers within the group:</p>
  
  <pre><code> Route::group(['namespace' =&gt; 'Admin'], function()
      {
          // Controllers Within The "App\Http\Controllers\Admin" Namespace
          Route::group(['namespace' =&gt; 'User'], function()
          {
              // Controllers Within The "App\Http\Controllers\Admin\User" Namespace
          });
      });
  </code></pre>
  
  <p><strong>Sub-Domain Routing</strong></p>
  
  <p>Route groups may also be used to route wildcard sub-domains. Sub-domains may be assigned route parameters just like route URIs, allowing you to capture a portion of the sub-domain for usage in your route or controller. The sub-domain may be specified using the domain key on the group attribute array:</p>
  
  <pre><code>Route::group(['domain' =&gt; '{account}.myapp.com'], function () {
      Route::get('user/{id}', function ($account, $id) {
          //
      });
  });    
  </code></pre>
  
  <p><strong>Route Prefixes</strong></p>
  
  <p>The prefix group array attribute may be used to prefix each route in the group with a given URI. For example, you may want to prefix all route URIs within the group with admin:</p>
  
  <pre><code>Route::group(['prefix' =&gt; 'admin'], function () {
      Route::get('users', function ()    {
          // Matches The "/admin/users" URL
      });
  });
  </code></pre>
  
  <p>You may also use the prefix parameter to specify common parameters for your grouped routes:</p>
  
  <pre><code>Route::group(['prefix' =&gt; 'accounts/{account_id}'], function () {
      Route::get('detail', function ($account_id)    {
          // Matches The accounts/{account_id}/detail URL
      });
  });
  </code></pre>
  
  <p>Ref: <a href="http://laravel.com/docs/5.1/routing" rel="noreferrer">http://laravel.com/docs/5.1/routing</a></p>