gpt4 book ai didi

laravel - 路由在auth无法在Laravel 4中工作之前设置的资源

转载 作者:行者123 更新时间:2023-12-04 04:59:44 25 4
gpt4 key购买 nike

我在routes.php中添加了它,希望它会检查页面的身份验证 session ,但是它不起作用。

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

然后我去 Controller ,以另一种方式工作。是工作。
class TicketController extends BaseController {

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

我能否知道在哪里可以获得有关Route::resource()的更多文档,它可以接受哪种类型的参数?

最佳答案

好...我找到了答案。



\vendor\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;
}

如您所见,它仅接受 onlyexcept争论。

如果要在route.php中归档相同的结果,可以按以下步骤完成
Route::group(array('before'=>'auth'), function() {   
Route::resource('ticket', 'TicketController');
});

关于laravel - 路由在auth无法在Laravel 4中工作之前设置的资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17438599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com