通过控制器的简单变量显示Laravel 4.2中的错误

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.

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) )