文章展示功能比较简单,分为两部分:文章列表特定文章展示文章列表。之前已经定义了路由:Route::get('/posts','PostsController@index');控制器:publicfunctionindex(){$posts=Post::latest()->get();returnview('posts.index',compact('posts'));}latest()方法等同于:$post=Post::orderBy('created_at','desc')->get();最后是视图:/resources/views/posts/index.blade.php@extends('layouts.master')@section('content')
{{str_limit($post->body,20)}}