2013-07-03 3 views
8

Ich habe dies in routes.php hinzugefügt, erwartet, dass es die Authentifizierungssitzung für die Seite überprüft, aber es funktioniert nicht.Route Ressourcen eingestellt, bevor Authentifizierung in Laravel funktioniert 4

Route::resource('ticket', 'TicketController', array('before' => 'auth')); 

Dann gehe ich zum Controller, auf eine andere Weise arbeiten. Es ist Arbeit.

Darf ich wissen, wo mehr Dokumentation in Bezug auf die Route :: resource() erhalten kann, welche Art von Argument kann es akzeptieren?

Antwort

21

OK ... Ich habe die Antwort gefunden. nur

in

\ Anbieter \ Laravel \ Framework \ src \ Illuminate \ Routing \ router.php

public function resource($resource, $controller, array $options = array()) 
    { 
     // If the resource name contains a slash, we will assume the developer wishes to 
     // register these resource routes with a prefix so we will set that up out of 
     // the box so they don't have to mess with it. Otherwise, we will continue. 
     if (str_contains($resource, '/')) 
     { 
      $this->prefixedResource($resource, $controller, $options); 

      return; 
     } 

     // We need to extract the base resource from the resource name. Nested resources 
     // are supported in the framework, but we need to know what name to use for a 
     // place-holder on the route wildcards, which should be the base resources. 
     $base = $this->getBaseResource($resource); 

     $defaults = $this->resourceDefaults; 

     foreach ($this->getResourceMethods($defaults, $options) as $method) 
     { 
      $this->{'addResource'.ucfirst($method)}($resource, $base, $controller); 
     } 
    } 

protected function getResourceMethods($defaults, $options) 
    { 
     if (isset($options['only'])) 
     { 
      return array_intersect($defaults, $options['only']); 
     } 
     elseif (isset($options['except'])) 
     { 
      return array_diff($defaults, $options['except']); 
     } 

     return $defaults; 
    } 

wie Sie sehen können, es nehmen nur only und except arguement.

Wenn Sie das gleiche Ergebnis in route.php archivieren möchten, können Sie es wie unten

Route::group(array('before'=>'auth'), function() { 
    Route::resource('ticket', 'TicketController'); 
}); 
+0

erfolgen Oder Sie Controllers before() Methode verwendet werden könnte. '$ this-> beforeFilter ('auth', ['außer' => 'zerstören']);'. Überprüfen Sie Devon's Kommentar unter [this link] (https://laracasts.com/index.php/discuss/channels/general-discussion/how-can-i-declare-a-before-filter-on-a-routeresource) –