2013-07-03 9 views
8

में काम नहीं करने से पहले मार्ग संसाधन सेट करें, मैंने इसे path.php में जोड़ा, उम्मीद है कि यह पृष्ठ के प्रमाणीकरण सत्र की जांच करेगा, हालांकि यह काम नहीं कर रहा है।लारवेल 4

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

फिर मैं नियंत्रक के पास जाता हूं, एक और तरीके से काम करता हूं। यही काम है।

class TicketController extends BaseController { 

public function __construct() 
{ 
    $this->beforeFilter('auth'); 
} 

क्या मुझे पता है कि रूट :: संसाधन() के बारे में अधिक दस्तावेज कहां प्राप्त कर सकते हैं, यह किस प्रकार का तर्क स्वीकार करने में सक्षम है?

उत्तर

21

ठीक है ... मुझे जवाब मिला।

में

\ विक्रेता \ laravel \ ढांचे \ src \ रोशन \ रूटिंग \ 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; 
    } 

के रूप में आप देख सकते हैं, यह केवल केवल only और except तर्क स्वीकार करते हैं।

आप route.php में एक ही परिणाम संग्रह करने के लिए चाहते हैं, यह

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

नीचे के रूप में किया जा सकता है या आप नियंत्रक beforeFilter() विधि इस्तेमाल कर सकते हैं। '$ this-> पहले फ़िल्टर ('auth', ['को छोड़कर' => 'नष्ट']);'। [इस लिंक] पर डेवन की टिप्पणी देखें (https://laracasts.com/index.php/discuss/channels/general-discussion/how-can-i-declare-a-before-filter-on-a-routeresource) –

संबंधित मुद्दे