laracasts / PHP-Vars-To-Js-Transformer

Transform PHP data to JavaScript.
https://packagist.org/packages/laracasts/utilities
MIT License
2.21k stars 219 forks source link

Apply only to certain views #97

Open robertmain opened 7 years ago

robertmain commented 7 years ago

I was under the impression that calling JavaScript::put() would affect only that controller action in which it was called. However, I'm finding that my unit tests are gaining because the JavaScript is finding its way into my API controller outputs.

My web routes file looks like this(I want to direct all web traffic to my SPA) and I wanted to pass some js variables through as well...

I figured that the route groups would isolate this from the API routes and stop what I was doing in here bleeding through, but perhaps I misunderstood?

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Route::get('/{catchall?}', function () {

    JavaScript::put([
        'APPTITLE' => htmlspecialchars_decode(config('app.name'))
    ]);

    return View::make('partials.index');
})->where('catchall', '(.*)');
;

Have i misunderstood something or misconfigured something here?