casa-parks/extract-routes 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

casa-parks/extract-routes

Composer 安装命令:

composer require casa-parks/extract-routes

包简介

Casa-Parks' Laravel route extracter.

README 文档

README

Build Status Total Downloads Latest Stable Version License

Introduction

Extract Routes is a simple provision of route listing, designed for providing use to the front end (IE: in JavaScript).

License

Extract Routes is open-sourced software licensed under the MIT license

Installation

To get started with Extract Routes, use Composer to add the package to your project's dependencies:

composer require casa-parks/extract-routes

Configuration

After installing, register the CasaParks\ExtractRoutes\ExtractRoutesServiceProvider in your config/app.php configuration file:

'providers' => [
    // Other service providers...

    CasaParks\ExtractRoutes\ExtractRoutesServiceProvider::class,
],

Basic Usage

Create a simple view composer, like so:

<?php

namespace App\Composers;

use CasaParks\ExtractRoutes\Service as RoutesExtractor;
use Illuminate\Contracts\View\View;

class RoutesComposer
{
    /**
     * The routes extractor.
     *
     * @var \CasaParks\ExtractRoutes\Service
     */
    protected $extractor;

    /**
     * Whether the data is cached or not.
     *
     * @var bool
     */
    protected $cached;

    /**
     * The view data.
     *
     * @var array
     */
    protected $data;

    /**
     * Creates a new routes composer.
     *
     * @param \CasaParks\ExtractRoutes\Service $extractor
     */
    public function __construct(RoutesExtractor $extractor)
    {
        $this->extractor = $extractor;
    }

    /**
     * Compose the view.
     *
     * @param \Illuminate\Contracts\View\View $view
     *
     * @return void
     */
    public function compose(View $view)
    {
        if (! $this->cached) {
            $this->cache();
        }

        $view->with($this->data);
    }

    /**
     * Cache the data.
     *
     * @return void
     */
    protected function cache()
    {
        $this->cached = true;

        // We don't want to include any admin / api routes.
        $routes = $this->extractor->filterOnly('middleware', 'guest', 'auth');

        $this->data = compact('routes');
    }
}

Add this view composer, into your app (or composer) service provider's boot method:

/**
 * Register any composers for your application.
 *
 * @return void
 */
public function boot()
{
    // ...

    // assuming `layout` is your common layout template.
    $this->app['view']->composer('layout', 'App\Composers\RoutesComposer');

    // ...
}

In your common layout template file:

<!-- ... -->
<head>
    <!-- ... -->

    <script>window.routes = {!! $routes->toJson() !!}</script>

    <!-- ... -->
</head>
<!-- ... -->

Then utilise as required in your JavaScript.

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固