Laravel 4 Laravel:将变量从控制器传递到视图

Laravel 4 Laravel:将变量从控制器传递到视图,laravel-4,Laravel 4,chatcontroller.php函数返回要查看的变量: 公共函数getChat() { $message=chat_messages::all(); 返回视图::make('home',compact($message)); } 这是我的路线: 路由::get('/getChat',array('as'=>'getChat','uses'=>'ChatController@getChat'));


chatcontroller.php函数返回要查看的变量:
公共函数getChat()
{
$message=chat_messages::all();
返回视图::make('home',compact($message));
}   
这是我的路线:
路由::get('/getChat',array('as'=>'getChat','uses'=>'ChatController@getChat'));                                                                      
这是我的主页。blade.php:
@扩展('layouts.main')
@节(“内容”)
欢迎来到主页!

你好{{Auth::user()->username}}!
    @foreach($msg形式的消息)
  • {{$msg['sender_username'],”说:“,$msg['message'],”
    “}”
  • @endforeach

@停止
验证路线以确保其使用新控制器:

Route::get('user/profile', array('uses' => 'MyDefinedController@showProfile'));

正如Matei Mihai所说,首先检查你的路线。 有两种不同的方式将数据传递到视图中

$items = Item::all();

// Option 1
return View::make('item.index', compact('items'));

// Option 2
return View::make('item.index')->with('items', $items); // same code as below

// Option 3
View::share('item.index', compact('items'));
return View::make('item.index);
您也可以这样做:

$this->data['items'] = Item::all();

return View::make('item.index', $this->data);

可能您的路由没有访问您定义的控制器。您必须将其更改为使用新控制器而不是家庭控制器。您可以提供一些代码吗?问题应该出在您的路线上。向我们展示一些代码,plz.chatcontroller.php函数返回要查看的变量: