本文整理汇总了PHP中Illuminate\Support\Facades\Route::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::filter方法的具体用法?PHP Route::filter怎么用?PHP Route::filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Route
的用法示例。
在下文中一共展示了Route::filter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
Route::filter('admin', function () {
if (Auth::guest()) {
if (Request::ajax()) {
return Response::make('Unauthorized', 401);
} else {
return redirect('/login');
}
}
if (Auth::user()->level !== 10) {
return redirect('/');
}
});
Route::filter('muhtar', function () {
if (Auth::guest()) {
if (Request::ajax()) {
return Response::make('Unauthorized', 401);
} else {
return redirect('/login');
}
}
if (Auth::user()->level !== 5) {
return redirect('/');
}
});
}
示例2: boot
public function boot()
{
$this->package('mrosati84/laradmin');
$prefix = Config::get('laradmin::prefix');
$namespace = Config::get('laradmin::namespace');
$entities = Config::get('laradmin::entities');
foreach ($entities as $entity => $properties) {
$fullClassName = $namespace . '\\' . $entity . 'Admin';
$baseAdminController = 'Mrosati84\\Laradmin\\BaseAdminController';
// register admin classes bindings
App::bind($fullClassName, function () use($fullClassName, $entity) {
return new $fullClassName($entity);
});
// register custom filters classes
App::bind('AuthenticationFilter', 'Mrosati84\\Laradmin\\Filters\\AuthenticationFilter');
// register custom route filters
Route::filter('laradmin.auth', 'AuthenticationFilter');
// register laradmin index route (just a redirect to default entity)
Route::get($prefix, array('as' => 'laradmin.index', function () use($prefix) {
return Redirect::route($prefix . '.' . strtolower(Config::get('laradmin::defaultEntity')) . '.index');
}));
// register entities routes
Route::group(array('prefix' => $prefix, 'before' => 'laradmin.auth'), function () use($entity, $fullClassName) {
Route::resource(strtolower($entity), $fullClassName);
});
}
}
示例3: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
Route::filter('autologin', function () {
if (!Auth::check()) {
$user = User::where('username', '=', 'admin')->firstOrFail();
Auth::login($user);
}
});
//
}
示例4: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
//
$settings = \Setting::first();
$root_dir = __DIR__ . '/../../../';
if (\Cookie::get('theme')) {
$theme = \Crypt::decrypt(\Cookie::get('theme'));
} else {
if ($settings->theme) {
$theme = $settings->theme;
}
}
//echo $theme; die();
// Add the theme view namespace
\Config::set('mail.from', ['address' => $settings->system_email, 'name' => $settings->website_name]);
@(include $root_dir . 'content/themes/' . $theme . '/functions.php');
View::addNamespace('Theme', $root_dir . 'content/themes/' . $theme);
Route::filter('auth', function () {
if (Auth::guest()) {
return Redirect::guest('login');
}
});
Route::filter('auth.basic', function () {
return Auth::basic();
});
Route::filter('if_logged_in_must_be_subscribed', function () {
if (!Auth::guest()) {
if (!Auth::user()->subscribed() && Auth::user()->role == 'subscriber') {
$username = Auth::user()->username;
return Redirect::to('user/' . $username . '/renew_subscription')->with(array('note' => 'Uh oh, looks like you don\'t have an active subscription, please renew to gain access to all content', 'note_type' => 'error'));
}
}
});
Route::filter('admin', function () {
if (!Auth::guest() && (Auth::user()->role == 'admin' || Auth::user()->role == 'demo')) {
} else {
return Redirect::to('/login');
}
});
Route::filter('demo', function () {
if (!Auth::guest() && Auth::user()->role == 'demo') {
return Redirect::back()->with(array('note' => 'Sorry, unfortunately this functionality is not available in demo accounts', 'note_type' => 'error'));
}
});
Route::filter('guest', function () {
if (Auth::check()) {
return Redirect::to('/');
}
});
}
示例5: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
// TODO: Is there a better way to do this?
Route::filter('cache.response.fetch', 'j0an\\LaravelCacheFilter\\ResponseCacheFilter@fetch');
Route::filter('cache.response.store', 'j0an\\LaravelCacheFilter\\ResponseCacheFilter@store');
}
示例6: array
<?php
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Route;
use Spescina\PlatformCore\Facades\Platform;
App::before(function ($request) {
Route::match(array('GET', 'POST'), '{model}/{action?}/{id?}', array('as' => 'module', function ($module, $action = 'listing', $id = null) {
return Platform::runModule($module, $action, $id);
}))->where(array('model' => '[a-z]+', 'action' => '[a-z]+', 'id' => '[0-9]+'));
});
Route::filter('platform-core', function () {
});
示例7: filters
/**
* Provide the needed filters.
*
* @return void
*/
public function filters()
{
// authentication filter used by the system
Route::filter('talkAuth', function () {
if (Auth::guest() || get_class(Auth::user()) != Config::get('talk::auth.model')) {
// redirect to login page
return Redirect::guest(Config::get('talk::routes.base') . '/auth/login');
}
});
// Make sure administrative accounts are admin only!
Route::filter('talkAdmin', function () {
if (Auth::guest() || Auth::user()->role != 10) {
return 'Admin Only';
// NO access to administration.
}
});
}
示例8: filterPermission
/**
* check for permission of modules
*/
protected function filterPermission()
{
Route::filter('hasAccess', function ($route, $request, $permission = null) {
if (Sentinel::check()) {
if (empty($permission) || Sentinel::hasAccess([$permission])) {
return;
}
}
if (empty($permission)) {
return redirect(route('loginBackend'))->withErrors('Please login first');
} else {
return redirect(route('accessDenied'))->withErrors('Permission denied.');
}
});
Route::filter('loggedIn', function ($route, $request, $permission = null) {
if (Sentinel::check()) {
if (empty($permission) || Sentinel::hasAccess([$permission])) {
return;
}
}
if (empty($permission)) {
return redirect(route('homepage'))->withErrors('Please login first');
} else {
return redirect(route('homepage'))->withErrors('Permission denied.');
}
});
}