PHPackages                             mikemclin/laravel-to-angular-constant - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mikemclin/laravel-to-angular-constant

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mikemclin/laravel-to-angular-constant
=====================================

Output Laravel data as an Angular constant

1.0.0(10y ago)0133MITPHPPHP &gt;=5.4.0

Since Aug 9Pushed 10y ago2 watchersCompare

[ Source](https://github.com/mikemclin/laravel-to-angular-constant)[ Packagist](https://packagist.org/packages/mikemclin/laravel-to-angular-constant)[ RSS](/packages/mikemclin-laravel-to-angular-constant/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel to Angular Constant
===========================

[](#laravel-to-angular-constant)

---

#### Based on: [laracasts/PHP-Vars-To-Js-Transformer](https://github.com/laracasts/PHP-Vars-To-Js-Transformer)

[](#based-on-laracastsphp-vars-to-js-transformer)

---

This package allows you to easily output Laravel 5 data as an Angular constant. This works great for sharing configuration settings, etc.

Basic Usage
-----------

[](#basic-usage)

You'll gain access to a helpful `Angular` facade, which you may use in your controllers.

```
public function index()
{
    Angular::put([
        'foo' => 'bar',
        'age' => 29
    ]);

    return View::make('footer');
}
```

Using the code above, the following will be outputted (based on the default config).

```
angular.module('laravelToAngularConstant', []).constant('DATA', {'foo', 'bar', 'age': 29});
```

Now, you would want to add that module as a submodule of your app.

```
angular.module('app', ['laravelToAngularConstant']);
```

How it works
------------

[](#how-it-works)

It prepends the data to the Laravel View that you define in the config (`footer` by default). Normally, you would include that view file into your master layout view, etc.

Installation
------------

[](#installation)

Begin by installing this package through Composer.

```
{
    "require": {
        "mikemclin/laravel-to-angular-constant": "~1.0.0"
    }
}
```

Next, setup the Laravel 5 service provider

```
// config/app.php

'providers' => [
    '...',
    'MikeMcLin\Angular\AngularServiceProvider'
];
```

Publish the default configuration.

```
php artisan vendor:publish
```

This will add a new configuration file to: `config/angular.php`.

```
