Support the ongoing development of Laravel.io →
Views Blade Forms

Hi,

I've setup a variable to use in my master view file. This works great inside of all my views, unless I'm using a form (currently at the front-page) to post to another route/page. When i hit the submit button and get the redirect to another route, the view::composer seems to skip the variable?

This is what i get when i submit

Undefined variable: NumDatabaseWords (View: C:\xampp\htdocs\pwcheck\app\views\layouts\main.blade.php) (View: C:\xampp\htdocs\pwcheck\app\views\layouts\main.blade.php)

filters.php

App::before(function($request)
{
View::composer('layouts.main', function($view)
   {
        $test = 'Hello World';
        $view->with('NumDatabaseWords', $test);
   });
});

in the master view file, i've also got the submit form (same viewfile where the variable is placed) and the form looks like this:

                    <div class="form_password_application text-center">
                        {{ Form::open( array('route' => 'check.index')) }}
                            <input type="text" name="pw_word" placeholder="Check your password..." class="password_check_input" />
                            <input type="submit" value="ENTER" class="password_check_submit" />
                        {{ Form::close() }}
                    </div> <!-- end form_password_application -->

Any suggestions on why i keep getting Undefined variable when i use the POST/Form? This does NOT happen if i don't use the post, then it all works fine..

Last updated 3 years ago.
0

I got this working after adding another view (the same view that says the variable was missing) inside of the View::composer using an array.

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Skofusen skofusen Joined 20 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.