在laravel 5中将数据从控制器传递到刀片时未定义可变错误[重复]

Allright,

Here is my index() method of UserController

public function index()
{

    $name = 'echoashu';

     return view('home', compact('name'));
}

As simple as that, and here my home.blade.php code

  <span class="info-box-number">{{$name}} </span>

This must work ideally as per documentation, but it returns undefined variable error

Undefined variable: name (View: C:\xampp\htdocs\laravel1esources\views\home.blade.php)

Any guess??

</div>

Give a man a fish and you feed him for a day; Teach a man to fish and you feed him for a lifetime

Here's Let me say how to debug(fish) in this situation.

1st Step :

Make sure that your call is right

You can do it by

Route::get('yourcall', 'UserController@index');

Before passing it inside the view, Just print something inside your controller like

public function index()
{
echo 'Whao ! I landed correctly';
}

2st Step :

Make sure that you see what you call

Now make your return to the view, Make sure that your view exists and have the name with extension like yourview.blade.php

You can do it by

return view('yourview', compact($YourValue));

So, You should have a view named as yourview.blade.php

Inside the blade you can get the passed value like

{{$YourValue}}  // If you have your file name as yourview.blade.php

or

<?php
echo $YourValue // If you have your file name as yourview.php
?>