vienna's avatar

PHP Vars to JS view not found

screenshot

I'm trying to load the variables into that app.blade.php, however I keep getting this error:

InvalidArgumentException in FileViewFinder.php line 137:
View [footer] not found.

With this being my javascript.php This is the package: https://github.com/laracasts/PHP-Vars-To-Js-Transformer

<?php

return [
    'bind_js_vars_to_this_view' => 'layouts.app',
    'js_namespace' => 'test'
];

I can't find what I'm doing wrong

0 likes
2 replies
jaydeluca's avatar

Have you tried using a View Composer?

App/ViewComposers/SharedDataComposer.php :

namespace App\Http\ViewComposers;
use Illuminate\Http\Request;
use Illuminate\View\View;
use JavaScript;

class SharedDataComposer
{
    /**
     * Bind data to the view.
     *
     * @param  Request  $request
     * @param  View  $view
     * @return void
     */
    public function compose(View $view)
    {
        if (auth()->user()) {

            JavaScript::put([
                'user' => auth()->user(),
            ]);
        }
    }
}

App/Providers/AppServiceProvider.php :

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        View::composer('layouts.app', 'App\Http\ViewComposers\SharedDataComposer');
    }
}
makeweb's avatar

For anyone else who experiences this issue: You must create a view partial called footer or whatever else you have chosen to call it for the package to bind to it. If you have nothing to put in that template you can just create an empty one.

Please or to participate in this conversation.