本文整理汇总了PHP中Illuminate\Support\Facades\Route::getRoutes方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::getRoutes方法的具体用法?PHP Route::getRoutes怎么用?PHP Route::getRoutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Route
的用法示例。
在下文中一共展示了Route::getRoutes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index()
{
$urls = [];
$routes = Route::getRoutes();
foreach ($routes as $route) {
$path = $route->getPath();
$actions = $route->getAction();
$params = $route->parameterNames();
$controller = $actions['controller'];
if (starts_with($path, '_') or str_contains($controller, 'RedirectController') or count($params)) {
continue;
}
$urls[] = url($path);
}
foreach (Campus::all() as $item) {
$urls[] = url($item->url);
}
foreach (Event::all() as $item) {
$urls[] = url($item->url);
}
foreach (Series::withDrafts()->get() as $item) {
$urls[] = url($item->url);
}
foreach (Staff::all() as $item) {
$urls[] = url($item->url);
}
foreach (MissionLocation::all() as $item) {
$urls[] = url($item->url);
}
foreach (Video::withDrafts()->get() as $item) {
$urls[] = url($item->url);
}
return response()->json($urls);
}
示例2: validate
/**
* Validates the user, password combination against the request.
*
* @param \Illuminate\Http\Request $request
* @param string $user
* @param string $password
*
* @return bool
*/
protected function validate($request, $user, $password)
{
// Get current route name
// Note: we do not have access to the current route in middleware, because
// it has not been fully dispatched, therefore we must use the backwards
// method of finding the route which matches the current request.
$routeName = null;
foreach (Route::getRoutes() as $route) {
if ($route->matches($request)) {
$routeName = $route->getName();
}
}
// If we have a named route
if ($routeName) {
// Check if route username and password are set
if ($routeUsername = env('ROUTE_RESTRICTOR_ROUTE_' . strtoupper($routeName) . '_USERNAME') && ($routePassword = env('ROUTE_RESTRICTOR_ROUTE_' . strtoupper($routeName) . '_PASSWORD'))) {
// Check against route password
if (trim($user) == $routeUsername && trim($password) == $routePassword) {
return true;
} else {
return false;
}
}
}
// Check if global username and password are set
if ($globalUsername = env('ROUTE_RESTRICTOR_GLOBAL_USERNAME') && ($globalPassword = env('ROUTE_RESTRICTOR_GLOBAL_PASSWORD'))) {
// Check against global password
if (trim($user) == $globalUsername && trim($password) == $globalPassword) {
return true;
} else {
return false;
}
}
return true;
}
示例3: getAvailableRoutes
private function getAvailableRoutes()
{
$routeList = array();
foreach (Route::getRoutes() as $route) {
if ($route->getName() !== null) {
$routeList[$route->getName()] = $route->getName();
}
}
return $routeList;
}
示例4: canRead
function canRead($routeName)
{
$route = Route::getRoutes()->getByName($routeName);
if ($route == null) {
return null;
}
$action = $route->getAction();
list($controller, $action) = explode('@', $action['controller']);
return app($controller)->getControllerModel()->allowsUserRead(auth()->user());
}
示例5: routeHasMiddlewareGroup
public function routeHasMiddlewareGroup($group)
{
$routes = Route::getRoutes()->getRoutes();
foreach ($routes as $route) {
$actions = (array) $route->getAction();
if (array_key_exists('middleware', $actions) && in_array($group, (array) $actions['middleware'])) {
return true;
}
}
return false;
}
示例6: getRouteData
/**
* Gets the route data
*
* @return array
*/
protected function getRouteData()
{
$allRoutes = Route::getRoutes();
$routeData = [];
foreach ($allRoutes as $route) {
if (!preg_match('/_debugbar/', $route->getUri())) {
$uri = preg_replace('#/{[a-z\\?]+}|{_missing}|/{_missing}#', '', $route->getUri());
$routeData[$route->getActionName()] = $uri;
}
}
return $routeData;
}
示例7: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
$this->setRootControllerNamespace();
if ($this->app->routesAreCached()) {
$this->loadCachedRoutes();
} else {
$this->loadRoutes();
$this->app->booted(function () {
Route::getRoutes()->refreshNameLookups();
});
}
}
示例8: handle
/**
* Handle the event.
*
* @param CacheEvent $event
* @return void
*/
public function handle(CacheEvent $event)
{
if (!Cache::get('routes') || !Cache::get('routes_simple')) {
$route_collection = Route::getRoutes();
$routes = [];
foreach ($route_collection as $route) {
if ($route->getName() && $route->getPrefix()) {
$group = explode('@', $route->getActionName());
$routes[$route->getPrefix()][$group[0]][$route->getName()] = $route->getName();
$routes_simple[] = $route->getName();
}
}
Cache::forever('routes', $routes);
Cache::forever('routes_simple', $routes_simple);
}
$this->initRoutesFormat();
}
示例9: generate
public static function generate()
{
$router = Route::getRoutes();
$routesByAction = array();
$routesByName = array();
foreach ($router as $route) {
if ($route->getActionName() != 'Closure') {
$routesByAction[$route->getActionName()]['route'] = str_replace('?}', '}', url($route->getPath()));
$routesByAction[$route->getActionName()]['parameters'] = $route->parameterNames();
}
if ($route->getName() != '') {
$routesByName[$route->getName()]['route'] = str_replace('?}', '}', url($route->getPath()));
$routesByName[$route->getName()]['parameters'] = $route->parameterNames();
}
}
return View::make('LaravelJsRouting::script', array('routesByAction' => $routesByAction, 'routesByName' => $routesByName));
}
示例10: getIndex
public function getIndex()
{
$routeCollection = Route::getRoutes();
echo "<table style='width:100%'>";
echo "<tr>";
echo "<td width='10%'><h4>HTTP Method</h4></td>";
echo "<td width='10%'><h4>Route</h4></td>";
echo "<td width='80%'><h4>Corresponding Action</h4></td>";
echo "</tr>";
foreach ($routeCollection as $value) {
echo "<tr>";
echo "<td>" . $value->getMethods()[0] . "</td>";
echo "<td>" . $value->getPath() . "</td>";
echo "<td>" . $value->getActionName() . "</td>";
echo "</tr>";
}
echo "</table>";
//return view('administracija.admin.index');
}
示例11: getManagePermissions
public function getManagePermissions()
{
$roles = Role::all();
$routes = Route::getRoutes();
$permissions = array();
$route_list = array();
$enabled_permissions = array();
foreach ($roles as $role) {
$enabled_permissions[$role->name] = $role->permissions()->lists('route');
}
foreach ($routes as $route) {
if (in_array($route->getActionName(), $route_list)) {
continue;
}
$route_list[] = $route->getActionName();
$permissions[] = array('route' => $route->getActionName(), 'display_route' => str_replace('App\\Http\\Controllers\\', '', $route->getActionName()));
}
return view('pages.admin.permissions', compact('permissions', 'roles', 'enabled_permissions'));
}
示例12: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$routeCollection = Route::getRoutes();
$data = array();
foreach ($routeCollection as $routes) {
if ($routes->getActionName() != "Closure") {
$rota = $routes->getActionName();
$data = array();
$exp = explode('\\', $rota);
$rota = $exp[3];
$data['rota'] = $rota;
$exp2 = explode("@", $exp[3]);
$controller = $exp2[0];
$action = $exp2[1];
$exp3 = explode('Controller', $controller);
$nome = $exp3[0];
$data['nome'] = $nome;
//dd(ngettext($data['nome']));
$data['descricao'] = ucfirst($action) . " " . $nome;
if ($action == "criar" || $action == "listar") {
$data['display'] = 1;
if ($action == "criar") {
$data['descricao'] = "Novo " . $nome;
}
}
$isExist = Perm::where('rota', $data['rota'])->count();
if ($isExist == 0) {
$perm = Perm::create($data);
if (!$perm) {
echo "erro ao salvar " . $data['descricao'] . "\n";
} else {
echo "\nSalvo " . $data['descricao'];
}
} else {
echo "rota " . $data['rota'] . " já foi salva em outro momento\n";
}
}
}
// return var_dump($data);
}
示例13: apis
/**
*/
public function apis()
{
$apis = [];
foreach (Route::getRoutes() as $route) {
$routeDomain = !empty($route->getAction()['domain']) ? $route->getAction()['domain'] : false;
if ($routeDomain && $routeDomain != \Request::server('HTTP_HOST')) {
continue;
}
// remove non apis and duplicate of PUT (ie PATCH)
if (stripos($route->uri(), 'api/') === 0 && !in_array('PATCH', $route->getMethods()) && array_key_exists('controller', $route->getAction())) {
$apis[] = new Api($route);
}
}
uasort($apis, function (Api $a, Api $b) {
$order = strcasecmp($a->group, $b->group);
$order = $order ?: strcmp($a->path, $b->path);
$order = $order ?: strcmp($this->methodOrder($a->httpMethod), $this->methodOrder($b->httpMethod));
return $order;
});
return array_values($apis);
}
示例14: run
public function run()
{
DB::table('permissions')->truncate();
$permissions = [];
$routeCollection = Route::getRoutes();
/*
** All route permission
*/
foreach ($routeCollection as $value) {
$action = $value->getAction();
if (isset($action['prefix']) && ($action['prefix'] = '/api/v1/' && isset($action['as']))) {
$route = explode(".", $action['as'], 3);
$route = $route[2];
$route_name = ucfirst(preg_replace('/\\./', ' ', $route));
$route_group = explode(" ", $route_name);
$route_group = $route_group[0];
$permissions[] = ['name' => $route_name, 'name_group' => $route_group, 'slug' => $route, 'slug_view' => 'app.' . $route, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")];
}
}
/*
** Custom route permission
*/
$custom_permission = [['slug_view' => 'app.multimedia.upload'], ['slug_view' => 'app.activityLogs.index']];
/*
** Re-define custom permission
*/
foreach ($custom_permission as $value) {
$slug_view = explode(".", $value['slug_view'], 2);
$name_group = explode(".", $slug_view[1]);
$route_name = ucfirst($name_group[0]) . ' ' . ucfirst($name_group[1]);
$name_group = ucfirst($name_group[0]);
$slug = $slug_view[1];
$permissions[] = ['name' => $route_name, 'name_group' => $name_group, 'slug' => $slug, 'slug_view' => $value['slug_view'], 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")];
}
Permission::insert($permissions);
}
示例15: compose
/**
* @param $view
*
* @return mixed
*/
public function compose(View $view)
{
/*
* Stores all the routes for selection, defaults are stored in config
*/
$allRoutes = $this->config->get('permissions.default');
/*
* Get all the routes in the application
*/
$routes = Route::getRoutes();
foreach ($routes as $route) {
$routeName = $route->getName();
/*
* Make sure the route has a name
*/
if ($routeName) {
/*
* Get the route filters
*/
$filters = $route->beforeFilters();
/*
* Make sure only routes guarded by the permission filter are shown
* in the route selection box
*/
if (array_key_exists('maintenance.permission', $filters)) {
/*
* Explode the route into segments
*/
$segments = explode('.', $routeName);
if (count($segments) >= 1) {
/*
* Pop the last segment off the route name
* so we can append a sentry wildcard to it ('*')
*/
array_pop($segments);
/*
* Set the array pointer to the last element
*/
end($segments);
/*
* Add the last element with the wildcard
*/
$segments[] = '*';
/*
* Implode the array back into dot notation
*/
$routeStar = implode('.', $segments);
/*
* Insert the route into the allRoutes array
*/
$allRoutes[$segments[0]][$routeStar] = $routeStar;
}
/*
* We'll use the first segment entry to group the routes together
* for easier navigation
*/
$allRoutes[$segments[0]][$routeName] = $routeName;
}
}
}
/*
* Return the view with the routes for selection
*/
return $view->with('allRoutes', $allRoutes);
}