Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

coderego's avatar

Laracasts PHP to JS Transformer

Has anyone used LaraCasts PHP to JS transformer in Laravel5? (https://github.com/laracasts/PHP-Vars-To-Js-Transformer) I am unable to get it to work. No data is reaching my view, no errors, just an empty view.

0 likes
8 replies
lancebutler2's avatar

I currently use it without problems. Can you give a little context with some code?

lancebutler2's avatar

Oops. I'm not sure if it's any different in L5. I just saw that. I'm using it in L4.2 without issue.

coderego's avatar

@lancebutler2 sure, that sounds prudent, heh.

Config/app.php

 'providers' => [
     'Laracasts\Utilities\JavaScript\JavascriptServiceProvider',

config/packages/laracasts/utilities/config.php

'bind_js_vars_to_this_view' => 'dashboard.partials.jsvars',
 'js_namespace' => 'elixir'

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Laracasts\Utilities\JavaScript\JavaScriptFacade as JavaScript;

class DashboardController extends Controller
{

    public function index()
    {
        //$investigationsPerUser = $this->organizationRepository->activeInvestigationsPerUser(Auth::user()->organization_id);
        $investigationsPerUser = Auth::user()->organization->activeInvestigationsPerUser();

        JavaScript::put(['investigationsPerUser' => $investigationsPerUser]);
    return view('dashboard.index');

View - dashboard.index extends a layout, which contains

@include('dashboard.partials.jsvars')

There is an empty file named jsvars.blade.php inside resources/views/dashboard/partials/

coderego's avatar

Yeah I had no problem in 4.2 either. Can't get it working on 5.1

coderego's avatar
coderego
OP
Best Answer
Level 6

Okay! The problem is:

I copied my config over from my old install at packages/laracasts/utilities

However, Jeffrey updated the code to generate a new config named javascript.php in the config directory. I didn't edit this. User error.

Learn from my fail :)

lancebutler2's avatar

Ah, good. I was just about to write that it seemed like you had everything alright. Glad you got it working.......and assured me a little more about upgrading my project to 5.1.

lancebutler2's avatar

The LTS and features will be worth it, but, yeah, it sounds like quite an undertaking.

Please or to participate in this conversation.