Closed mschink closed 7 years ago
I tested with two Laravel 5.3 projects, one small site and a completely new install, and it worked.
Some pointers:
Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class,
as I have a later PHP version. Make absolutely sure you have this as above.
I had to create a blank footer.blade.php. The documentation is a bit unclear, but if you don't have that file, create it (and blank worked).
Your actual error of class not found sounds like something fundamental is wrong.
I didn't need to publish to get it working.
Thanks for the detailed response.
I did try the ::class
notation for later versions of PHP, but no luck with that. I currently have a file footer.blade.php in views/templates/
so I'm not sure if this requirement is directory-sensitive.
I will try doing this with a brand new project, and report the results. These things might be nice to include in the documentation so there's less clutter of questions regarding setting up the package!
Cheers.
UPDATE: For anyone else having similar issues as I had above, I highly suggest rebuilding your app from scratch. As far as I know, I did nothing different, but it's working now. Consider this issue resolved, though, an update to the documentation would be great for first-timers who haven't installed a 3rd party package via Composer.
I've just been tearing my hair out for the past hour. It just wasn't running the boot method on the service provider.
Eventually I got it to work by running
php artisan config:clear php artisan config:cache php artisan clear-compiled
I am also having the same problem? @mschink did you solve it?
@Mutasim0520 I think if you follow what @jamesmorrish said above you'll find it works. It could be related to caching issues or perhaps my unfamiliarity with using Composer. Because I have my entire project versioned on Git, the last resort was simple enough: clone a new copy of the project and see if it works there.
@eugenevdm to make your post a little clearer: I only got it working if the code is within the footer.blade.php file u mentioned.
EDIT: behaviour is accordingly, the configuration is bound to
'bind_js_vars_to_this_view' => 'footer',
(README.md)
Laravel: 5.4 PHP-Vars-To-Js-Transformer: 2.1
'providers' => [
...,
Laracasts\Utilities\JavaScript\JavaScriptServiceProvider::class,
...
];
Route::get('/', function () {
JavaScript::put(['foo' => 'bar']);
return view('welcome');
});
@include ('footer')
</body>
<script>console.log(foo);</script>
bar
I've followed the documentation very closely and it's still missing something, perhaps namespace related?
Here's my composer.json:
Then in cmd:
results in
vendor\laracasts\utilities\
as expectedThen I modify app.php:
Here's the part where I think there's definitely some issue in 5.3, because
php artisan vendor:publish
gives the following output:No mention of the config for javascript, and there's no javascript.php file copied to
config/
But maybe it will still work, so in my
IndexController.php
Results in the following error: