我在routes.php中添加了这个,期望它会检查页面的身份验证会话,但它无法正常工作。
Route::resource('ticket', 'TicketController', array('before' => 'auth') );
然后我去控制器,以另一种方式工作。这是工作。
class TicketController extends BaseController {
public function __construct()
{
$this->beforeFilter('auth');
}
我可以知道哪里可以获得更多关于Route :: resource()的文档,它能够接受哪种类型的参数?
答案 0 :(得分:22)
好的......我找到了答案。
在
\厂商\ 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');
});