Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
代码的结果不会显示在浏览器中,并且在laravel中没有错误_Laravel_Laravel 5_Laravel 4_Laravel 5.2_Laravel 5.1 - Fatal编程技术网

代码的结果不会显示在浏览器中,并且在laravel中没有错误

代码的结果不会显示在浏览器中,并且在laravel中没有错误,laravel,laravel-5,laravel-4,laravel-5.2,laravel-5.1,Laravel,Laravel 5,Laravel 4,Laravel 5.2,Laravel 5.1,这是postController.php代码: public function index() { $posts = post::orderBy('created_at', 'DESC')->get(); return view('posts.index', compact('posts')); } public function index() { $posts = post::orderBy('created_at', 'DESC')->ge

这是postController.php代码:

public function index()
{


    $posts = post::orderBy('created_at', 'DESC')->get();


    return view('posts.index', compact('posts'));

}
public function index()
{

    $posts = post::orderBy('created_at', 'DESC')->get();

    return $posts;   

}
我还制作了一个路由(web.php):

这是视图(index.blade.php)代码:

它显示了从数据库,但也有问题在这里!为什么代码在浏览器中显示不整齐


尝试在post.index.blade上使用
{{dd($posts)}
。如果您在blade上获得$posts变量,则一切都将受到罚款。如果不超过
dd(“某些测量信息”)
则将其输入索引()中,以检查您的索引方法是否实际获得调用


如果您的index()方法没有打印
dd(“某些消息”)
而不是在terminal type
php artisan route:list中,则检查您的路由是否带有前缀。

所有相关代码都需要直接作为文本发布在此处,理想情况下,作为一个。让我们看看在我编写php artisan route时的post Model可能的副本:list这是我在示例数据中看到的,我可以看到对象在数组中。因此,请尝试
$posts=post::orderBy('created_at','DESC')->get()->first()
或在blade中执行此操作
@foreach($posts[0]作为$post)
@section('content')

    @foreach($posts as $post)

    <div class="panel">
       <div class="panel-heading">
           <h3>{{ $post -> title }}</h3>
       </div>

       <div class="panel-body">
              {{ $post -> body }}
       </div>
    </div>

    @endforeach

@endsection
public function index()
{

    $posts = post::orderBy('created_at', 'DESC')->get();

    return $posts;   

}