本文整理汇总了PHP中Illuminate\Routing\Router::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::filter方法的具体用法?PHP Router::filter怎么用?PHP Router::filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Routing\Router
的用法示例。
在下文中一共展示了Router::filter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
//
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
$router->filter('auth.basic', function () {
return Auth::basic();
});
/*
|--------------------------------------------------------------------------
| Guest Filter
|--------------------------------------------------------------------------
|
| The "guest" filter is the counterpart of the authentication filters as
| it simply checks that the current user is not logged in. A redirect
| response will be issued if they are, which you may freely change.
|
*/
$router->filter('guest', function () {
if (Auth::check()) {
return Redirect::to('/');
}
});
parent::boot($router);
}
示例2: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
$router->filter('auth', function () {
if (Auth::guest()) {
if (Request::ajax()) {
return Response::make('Unauthorized', 401);
} else {
return Redirect::guest('/');
}
}
});
$router->filter('auth.basic', function () {
return Auth::basic();
});
$router->filter('guest', function () {
if (Auth::check()) {
return Redirect::to('/');
}
});
$router->filter('admin', function () {
if (Auth::check()) {
if (Auth::user()->email != "ceesco53@gmail.com") {
return Redirect::to('/');
}
} else {
return Redirect::to('/');
}
});
parent::boot($router);
}
示例3: map
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
$router->filter("userauth", function () {
if (!Auth::user()->check()) {
return redirect("");
}
});
$router->filter("organizationauth", function () {
if (!Auth::organization()->check()) {
return redirect("/organizations/login");
}
});
}
示例4: map
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
$router->filter('authuser', function () {
if (!\Auth::check()) {
return redirect()->guest('login');
}
});
$router->filter('filtername', function ($route, $request, $value) {
$array = explode('-', $value);
// use - for delimiter
return $array;
// do whatever here
});
}
示例5: setupFilters
/**
* Setup the filters.
*
* @param \Illuminate\Routing\Router $router
* @param \GrahamCampbell\Throttle\Throttle $throttle
*
* @return void
*/
protected function setupFilters(Router $router, Throttle $throttle)
{
$router->filter('throttle', function ($route, $request, $limit = 10, $time = 60) use($throttle) {
if (!$throttle->attempt($request, $limit, $time)) {
throw new TooManyRequestsHttpException($time * 60, 'Rate limit exceed.');
}
});
}
示例6: register
public function register(Router $router, Resolver $resolver)
{
$reflection = new ReflectionMethodsFilter($this);
foreach ($methods = $reflection->filterPrefix($this->getPrefix()) as $method) {
$router->filter($method, $resolver->methodToClosure($this, $method));
}
$this->registered = true;
}
示例7: registerFilters
/**
* Register the filters.
*
* @param Router $router
* @return void
*/
public function registerFilters(Router $router)
{
foreach ($this->filters as $module => $filters) {
foreach ($filters as $name => $filter) {
$class = "Modules\\{$module}\\Http\\Filters\\{$filter}";
$router->filter($name, $class);
}
}
}
示例8: map
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
$router->filter('notlogin', function () {
if (auth()->user()) {
return redirect(athr . '/categories');
}
});
}
示例9: registerRouteFilters
/**
* Register route filters.
*
* @param \Illuminate\Routing\Router $router
*
* @return void
*/
protected function registerRouteFilters(Router $router)
{
foreach ((array) $this->before as $before) {
$router->before($before);
}
foreach ((array) $this->after as $after) {
$router->after($after);
}
foreach ((array) $this->filters as $name => $filter) {
$router->filter($name, $filter);
}
}
示例10: filter
/**
* Register a new filter with the router.
*
* @param string $name
* @param string|callable $callback
* @return void
* @deprecated since version 5.1.
* @static
*/
public static function filter($name, $callback)
{
\Illuminate\Routing\Router::filter($name, $callback);
}