2017 © Pedro Peláez
 

library extract-routes

Casa-Parks' Laravel route extracter.

image

casa-parks/extract-routes

Casa-Parks' Laravel route extracter.

  • Wednesday, March 15, 2017
  • by ConnorVG
  • Repository
  • 0 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Build Status Total Downloads Latest Stable Version License , (*1)

Introduction

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

License

Extract Routes is open-sourced software licensed under the MIT license, (*3)

Installation

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

composer require casa-parks/extract-routes

Configuration

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

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

    CasaParks\ExtractRoutes\ExtractRoutesServiceProvider::class,
],

Basic Usage

Create a simple view composer, like so:, (*6)

<?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:, (*7)

/**
 * 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:, (*8)


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

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

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

Then utilise as required in your JavaScript., (*9)

The Versions

15/03 2017

dev-master

9999999-dev

Casa-Parks' Laravel route extracter.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel route extract

15/03 2017

dev-develop

dev-develop

Casa-Parks' Laravel route extracter.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel route extract

15/03 2017

1.0.0

1.0.0.0

Casa-Parks' Laravel route extracter.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel route extract