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

Not working laravel 5.4 mac with valet? #102

Closed jesseyofferenvan closed 7 years ago

jesseyofferenvan commented 7 years ago

So I just have a freshly installed project with laravel valet, using laravel 5.4. Running the following commands in the exact order.

npm install
composer require laracasts/utilities
php artisan vendor:publish

Now I edit the config/app.php and add

'Laracasts\Utilities\JavaScript\JavaScriptServiceProvider'

to the end of the list.

Next I edit my routes/web.php to do a quick test and edit it to the following

use Javascript;
Route::get('/', function () {
    Javascript::put([
        'foo' => 'bar',
        'user' => 'My sweet user',
        'age' => 29
    ]);
    return view('welcome');
});

Now I also published the config and edited it to run on the welcome page instead of the footer.

Now I get the following error:

The use statement with non-compound name 'Javascript' has no effect
TinoN commented 7 years ago

Try 'Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class' in config/app.php.

For me it did the trick, but in the end I wasn't able to access the variables in my component vue file :(

jesseyofferenvan commented 7 years ago

I have it working something somehow, I haven't touched the code for 2 days, all I did was running artisan commands and it worked, perhaps try running: php artisan config:clear; php artisan cache:clear; php artisan config:cache

It works like a charm for me now 👍

TinoN commented 7 years ago

Thanks for your reply, unfortunately it didn't work for me. The only way I got it somewhat working is as I described in PHP-Vars-To-Js-Transformer/issues/91 :(

EDIT: behaviour is accordingly, the configuration is bound to

    'bind_js_vars_to_this_view' => 'footer',

(README.md)

jesseyofferenvan commented 7 years ago

Ah yeah, I already had that changed to welcome for my case to do a quicker test run, good to hear its working now then!