1
我刚开始使用Laravel,并试图从数据库中检索值并试图通过路由器在视图上输出它们时卡住了。这里是我的代码在路由器:使用刀模板鉴于Laravel:无法将数组从数据库从路由器传递到视图
Route::get('/', function(){
$posts = DB::select("select title from posts");
return View::make("hello", $posts);
});
代码:
@extends('master')
@section('title')
@foreach ($posts as $post) {
{{ $post->title }}
@endforeach
@endsection
我试图检查查询,它运行完美,但我得到的观看页面上的未定义的变量错误。
它是什么,我做错了,我该如何改正呢?请帮助..
Give this Before。 $ posts = DB :: table('posts') - > select('title') - > get(); –
错误已更改,但仍无法正常工作。 http://puu.sh/7eKGI.png – Gaurav