0

I am trying to pass a simple $name variable via controller.

Controller file:

if($validator->fails())
{
    $this->layout->content = View::make('admin.login' )->with('name',$name);
}

Note:

protected $layout = 'admin.layout.login_master';

$layout is class member for login page layout

View file:

@section('content')
<h1>Admin Login</h1>

                    {{ Form::open(array('url' => 'admin/login','method'=>'post')) }}
                    <div style="color:red">
                    {{ $name }}
                    </div>
                        <div id="row">
                       <div class="form-group">
                            {{ Form::label('username', 'Username') }}
                            {{ Form::text('username', '', array('class' => 'form-control')) }}
                        </div>
                        </div>

                        <div id="row">
                        <div class="form-group">
                            {{ Form::label('password') }}
                            {{ Form::password('password', array('class' => 'form-control')) }}
                        </div>
                        </div>

                        <div id="row">
                        <div class="form-group">
                            {{ Form::submit('Login',array('class'=>'btn btn-default')) }}

                        </div>
                        </div>

                    {{ Form::close() }}

@stop

it's showing an error in the log file:

Next exception 'ErrorException' with message 'Undefined variable: name (View: C:\xampp\htdocs\portfolio\app\views\admin\login.blade.php)' in C:\xampp\htdocs\portfolio\app\storage\views\94976abb04474489c25123342a2993a1:7
Stack trace:

and in the browser it's showing:

Whoops, looks like something went wrong.

1 Answer 1

0

If this is not working, there are other ways also to pass variables from controller to view in Laravel if you have $name variable defined and want to access in views with $name then u can try any of following

$this->layout->content = View::make('admin.login' )->withName($name);
$this->layout->content = View::make('admin.login' )->with(compact('name'));
$this->layout->content = View::make('admin.login', array('name'=>$name) )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.